view browser_side/register.py @ 19:e8e3704eb97f

Added basic chat panel - the chat panel show history, timestamp, and nickname (pretty similar to primitivus and wix chat window) - JID has be rewritten to work with pyjamas, and is now in browser_side directory - a widget can now be selected: the message send in uniBox will be sent to it if there is no explicit target prefix ("@something") - a basic status panel is added under the uniBox, but not used yet
author Goffi <goffi@goffi.org>
date Sat, 16 Apr 2011 01:46:01 +0200
parents c725b702e927
children 71a9cc9b9d57
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.passBox = PasswordTextBox()
        self.passBox.setName("password")
        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)