view browser_side/register.py @ 42:71a9cc9b9d57

Browser side: Tarot game - draw game managed - we can now play continuously \o/
author Goffi <goffi@goffi.org>
date Mon, 23 May 2011 00:45:19 +0200
parents c725b702e927
children a7ff1e6f1229
line wrap: on
line source

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Libervia: a Salut à Toi frontend
Copyright (C) 2011  Jérôme Poisson (goffi@goffi.org)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

#This page manage subscription and new account creation
import pyjd # this is dummy in pyjs

from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.Grid import Grid
from pyjamas.ui.PasswordTextBox import PasswordTextBox
from pyjamas.ui.TextBox import TextBox
from pyjamas.ui.FormPanel import FormPanel
from pyjamas.ui.Button import Button
from pyjamas.ui.DialogBox import DialogBox
from pyjamas import Window
from pyjamas.ui import HasAlignment




class RegisterPanel(FormPanel):

    def __init__(self, callback):
        """
        @param callback: method to call if login successful
        """
        FormPanel.__init__(self)
        self.callback = callback
        self.setMethod(FormPanel.METHOD_POST)
        vPanel = VerticalPanel()
        vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
        self.loginBox = TextBox()
        self.loginBox.setName("login")
        self.loginBox.setText("goffi_local")
        self.passBox = PasswordTextBox()
        self.passBox.setName("password")
        self.passBox.setText("toto")
        grid = Grid(2, 2)
        grid.setText(0,0,"Login:")
        grid.setWidget(0,1, self.loginBox)
        grid.setText(1,0, "Password:")
        grid.setWidget(1,1, self.passBox)
        vPanel.add(grid)
        login_but = Button("Login", getattr(self, "onLogin"))
        vPanel.add(login_but)
        self.add(vPanel)
        self.addFormHandler(self)
        self.setAction('register_api/login')

    def onLogin(self):
        self.submit()
    
    def onSubmit(self, event):
        pass

    def onSubmitComplete(self, event):
        result = event.getResults()
        if result == "AUTH ERROR":
            Window.alert('You login and/or password is incorrect. Please try again')
        elif result == "LOGGED":
            self.callback()
        else:
            Window.alert('Submit error: %s' % result)

class RegisterBox(DialogBox):

    def __init__(self, callback, *args,**kwargs):
        DialogBox.__init__(self,*args,**kwargs)
        _form = RegisterPanel(callback)
        self.setHTML('<b>You are not identified, please log in</b>')
        self.setWidget(_form)