changeset 483:a594780d5e64

Login macro, login/logout/UserPreferences actions imported from: moin--main--1.5--patch-487
author Thomas Waldmann <tw@waldmann-edv.de>
date Sun, 19 Mar 2006 01:21:38 +0000
parents 3c08c0657dad
children a83f4ebb4955
files ChangeLog MoinMoin/action/UserPreferences.py MoinMoin/action/login.py MoinMoin/action/logout.py MoinMoin/macro/Login.py MoinMoin/request.py MoinMoin/theme/__init__.py MoinMoin/userform.py docs/CHANGES
diffstat 9 files changed, 238 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Mar 18 22:24:02 2006 +0000
+++ b/ChangeLog	Sun Mar 19 01:21:38 2006 +0000
@@ -2,6 +2,29 @@
 # arch-tag: automatic-ChangeLog--arch@arch.thinkmo.de--2003-archives/moin--main--1.5
 #
 
+2006-03-19 02:21:38 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-487
+
+    Summary:
+      Login macro, login/logout/UserPreferences actions
+    Revision:
+      moin--main--1.5--patch-487
+
+    Login macro, login/logout/UserPreferences actions
+    
+
+    new files:
+     MoinMoin/action/.arch-ids/UserPreferences.py.id
+     MoinMoin/action/.arch-ids/login.py.id
+     MoinMoin/action/.arch-ids/logout.py.id
+     MoinMoin/action/UserPreferences.py MoinMoin/action/login.py
+     MoinMoin/action/logout.py MoinMoin/macro/.arch-ids/Login.py.id
+     MoinMoin/macro/Login.py
+
+    modified files:
+     ChangeLog MoinMoin/request.py MoinMoin/theme/__init__.py
+     MoinMoin/userform.py docs/CHANGES
+
+
 2006-03-18 23:24:02 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-486
 
     Summary:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/UserPreferences.py	Sun Mar 19 01:21:38 2006 +0000
@@ -0,0 +1,23 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - UserPreferences action
+    
+    This is a simple plugin, that adds a "UserPreferences" action.
+    This action will display the UserPreferences page (or appropriate
+    page in the reader's language), so that the user can login, or
+    change his/her preferences.
+
+    However, as it is an action, the page that is displayed is not 
+    changed. After submitting the form, the user is presented the
+    same page he/she was seeing before, and the trail is not modified.
+
+    @copyright: 2006 by Radomir Dopieralski
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin import wikiutil
+
+def execute(pagename, request):
+    page = wikiutil.getSysPage(request, 'UserPreferences')
+    page.send_page(request)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/login.py	Sun Mar 19 01:21:38 2006 +0000
@@ -0,0 +1,73 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - login action
+
+    The real login is done in MoinMoin.request.
+    Here is only some user notification in case something went wrong.
+
+    @copyright: 2005-2006 by Radomirs Cirskis <nad2000@gmail.com>
+    @copyright: 2006 by Thomas Waldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin import user, wikiutil, userform
+from MoinMoin.Page import Page
+
+def execute(pagename, request):
+    return LoginHandler(pagename, request).handle()
+
+class LoginHandler:
+    def __init__(self, pagename, request):
+        self.request = request
+        self._ = request.getText
+        self.cfg = request.cfg
+        self.pagename = pagename
+        self.page = Page(request, pagename)
+
+    def handle(self):
+        _ = self._
+        request = self.request
+        form = request.form
+
+        error = None
+
+        islogin = form.get('login', [''])[0]
+
+        if islogin: # user pressed login button
+            # Trying to login with a user name and a password
+            # Require valid user name
+            name = form.get('name', [''])[0]
+            if not user.isValidName(request, name):
+                 error = _("""Invalid user name {{{'%s'}}}.
+Name may contain any Unicode alpha numeric character, with optional one
+space between words. Group page name is not allowed.""") % name
+
+            # Check that user exists
+            elif not user.getUserId(request, name):
+                error = _('Unknown user name: {{{"%s"}}}. Please enter'
+                             ' user name and password.') % name
+
+            # Require password
+            else:
+                password = form.get('password',[None])[0]
+                if not password:
+                    error = _("Missing password. Please enter user name and"
+                             " password.")
+                else:
+                    if not request.user.valid:
+                        error = _("Sorry, wrong password.")
+
+            return self.page.send_page(request, msg=error)
+        
+        else: # show login form
+            request.http_headers()
+            wikiutil.send_title(request, _("Login"), pagename=self.pagename)
+            # Start content (important for RTL support)
+            request.write(request.formatter.startContent("content"))
+            
+            request.write(userform.getLogin(request))
+            
+            # End content and send footer
+            request.write(request.formatter.endContent())
+            wikiutil.send_footer(request, self.pagename)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/action/logout.py	Sun Mar 19 01:21:38 2006 +0000
@@ -0,0 +1,27 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - logout action
+
+    The real logout is done in MoinMoin.request.
+    Here is just some stuff to notify the user.
+
+    @copyright: 2005-2006 by Radomirs Cirskis <nad2000@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.Page import Page
+
+def execute( pagename, request):
+    return LogoutHandler(pagename, request).handle()
+
+class LogoutHandler:
+    def __init__(self, pagename, request):
+        self.request = request
+        self._ = request.getText
+        self.page = Page(request,pagename)
+
+    def handle(self):
+        _ = self._
+        message = _("You are now logged out.")
+        return self.page.send_page(self.request, msg=message)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/macro/Login.py	Sun Mar 19 01:21:38 2006 +0000
@@ -0,0 +1,19 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - login form
+
+    @copyright: 2005-2006 by Radomirs Cirskis <nad2000@gmail.com>
+    @license: GNU GPL, see COPYING for details.
+"""
+from MoinMoin.widget import html
+from MoinMoin import userform
+
+def execute(macro, args):
+    """ Show the login form (but only when not logged in) """
+    request = macro.request
+    if request.user.valid:
+        data = u''
+    else:
+        data = userform.getLogin(request)
+    return data
+
--- a/MoinMoin/request.py	Sat Mar 18 22:24:02 2006 +0000
+++ b/MoinMoin/request.py	Sun Mar 19 01:21:38 2006 +0000
@@ -508,11 +508,6 @@
         u = self.get_user_default_unknown(name=name, password=password,
                                           login=login, logout=logout,
                                           user_obj=None)
-        if login and u.valid: # user login successful
-            # we redirect to base url to either show page_front_page or
-            # jump to the last page the user visited last time
-            self.http_redirect(self.getBaseURL())
-            self.finish()
         return u
     
     def get_user_default_unknown(self, **kw):
--- a/MoinMoin/theme/__init__.py	Sat Mar 18 22:24:02 2006 +0000
+++ b/MoinMoin/theme/__init__.py	Sun Mar 19 01:21:38 2006 +0000
@@ -203,7 +203,6 @@
         """
         request = self.request
         _ = request.getText
-        preferencesPage = wikiutil.getSysPage(request, 'UserPreferences')
         
         userlinks = []
         # Add username/homepage link for registered users. We don't care
@@ -219,20 +218,14 @@
                         request.formatter.text(name) +
                         request.formatter.interwikilink(0))
             userlinks.append(homelink)        
-            # Set pref page to localized Preferences page
-            title = preferencesPage.split_title(request)
-            userlinks.append(preferencesPage.link_to(request, text=title, id="userprefs"))
             
         if request.cfg.show_login:
             if request.user.valid:
-                userlinks.append("""\
-<form id="logout" action="" method="POST">
-<input type="hidden" name="action" value="userform">
-<input type="submit" name="logout" value="%(logout)s">
-</form>
-""" % { 'logout': _('Logout') })
+                userlinks.append(d['page'].link_to(request, text=_('Logout', formatted=False),
+                                                   querystr={'action': 'logout', 'logout': 'logout'}, id="logout"))
             else:
-                userlinks.append(preferencesPage.link_to(request, text=_("Login"), id="login"))
+                userlinks.append(d['page'].link_to(request, text=_("Login", formatted=False),
+                                                   querystr={'action': 'login'}, id="login"))
 
         userlinks = [u'<li>%s</li>' % link for link in userlinks]
         html = u'<ul id="username">%s</ul>' % ''.join(userlinks)
--- a/MoinMoin/userform.py	Sat Mar 18 22:24:02 2006 +0000
+++ b/MoinMoin/userform.py	Sun Mar 19 01:21:38 2006 +0000
@@ -581,7 +581,7 @@
             buttons = [
                 # IMPORTANT: login should be first to be the default
                 # button when a user hits ENTER.
-                ('login', _('Login')),
+                #('login', _('Login')),  # we now have a Login macro
                 ("create", _('Create Profile')),
             ]
             for key, label, type, length, textafter in self.cfg.user_form_fields:
@@ -618,6 +618,66 @@
     return UserSettings(request).asHTML(create_only=create_only)
 
 
+class Login:
+    """ User login. """
+
+    def __init__(self, request):
+        """ Initialize user settings form.
+        """
+        self.request = request
+        self._ = request.getText
+        self.cfg = request.cfg
+
+    def make_row(self, label, cell, **kw):
+        """ Create a row in the form table.
+        """
+        self._table.append(html.TR().extend([
+            html.TD(**kw).extend([html.B().append(label), '   ']),
+            html.TD().extend(cell),
+        ]))
+
+
+    def asHTML(self):
+        """ Create the complete HTML form code. """
+        _ = self._
+        sn = self.request.getScriptname()
+        pi = self.request.getPathinfo()
+        action = u"%s%s" % (sn, pi)
+        self._form = html.FORM(action=action)
+        self._table = html.TABLE(border="0")
+
+        # Use the user interface language and direction
+        lang_attr = self.request.theme.ui_lang_attr()
+        self._form.append(html.Raw('<div class="userprefs"%s>' % lang_attr))
+
+        self._form.append(html.INPUT(type="hidden", name="action", value="login"))
+        self._form.append(self._table)
+        self._form.append(html.Raw("</div>"))
+
+        self.make_row(_('Name'), [
+            html.INPUT(
+                type="text", size="32", name="name",
+            ),
+        ])
+
+        self.make_row(_('Password'), [
+            html.INPUT(
+                type="password", size="32", name="password",
+            ),
+        ])
+
+        self.make_row('', [
+            html.INPUT(
+                type="submit", name='login', value=_('Login')
+            ),
+        ])
+
+        return unicode(self._form)
+
+def getLogin(request):
+    """ Return HTML code for the login. """
+    return Login(request).asHTML()
+
 #############################################################################
 ### User account administration
 #############################################################################
--- a/docs/CHANGES	Sat Mar 18 22:24:02 2006 +0000
+++ b/docs/CHANGES	Sun Mar 19 01:21:38 2006 +0000
@@ -34,7 +34,14 @@
 
 Version 1.5.current:
   New features:
-    * show frontpage or last page visited after successful login
+    * Login and Logout are actions now, therefore you stay on the page where
+      you were before.
+    * UserPreferences is also an action now and moved from top border (in
+      modern theme) to the "more actions" dropdown menu. You also stay on the
+      same page.
+    * There is also a [[Login]] macro now. You can put it on any page you want
+      and if the user is not logged in, it renders the login form. If the user
+      is logged in, it doesn't render anything.
     * attachment search using lupy (lupy_search = 1 in your config)
       Title search will also search attachment filenames.
       Full text search will also search attachment contents.