annotate MoinMoin/action/login.py @ 949:cbbde07e00c4

whitespace-only cleanup, small style changes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 17 Jul 2006 04:01:34 +0200
parents b270396abba9
children ecece5db5288
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
3 MoinMoin - login action
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
5 The real login is done in MoinMoin.request.
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
6 Here is only some user notification in case something went wrong.
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8 @copyright: 2005-2006 by Radomirs Cirskis <nad2000@gmail.com>
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
9 @copyright: 2006 by Thomas Waldmann
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10 @license: GNU GPL, see COPYING for details.
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
11 """
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
12
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
13 from MoinMoin import user, wikiutil, userform
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
14 from MoinMoin.Page import Page
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
15
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
16 def execute(pagename, request):
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
17 return LoginHandler(pagename, request).handle()
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
18
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
19 class LoginHandler:
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
20 def __init__(self, pagename, request):
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
21 self.request = request
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
22 self._ = request.getText
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
23 self.cfg = request.cfg
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
24 self.pagename = pagename
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
25 self.page = Page(request, pagename)
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
26
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
27 def handle(self):
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
28 _ = self._
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
29 request = self.request
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
30 form = request.form
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
31
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
32 error = None
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
33
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
34 islogin = form.get('login', [''])[0]
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
35
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
36 if islogin: # user pressed login button
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
37 # Trying to login with a user name and a password
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
38 # Require valid user name
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
39 name = form.get('name', [''])[0]
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
40 if not user.isValidName(request, name):
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
41 error = _("""Invalid user name {{{'%s'}}}.
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
42 Name may contain any Unicode alpha numeric character, with optional one
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
43 space between words. Group page name is not allowed.""") % name
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
44
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
45 # Check that user exists
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
46 elif not user.getUserId(request, name):
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
47 error = _('Unknown user name: {{{"%s"}}}. Please enter'
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
48 ' user name and password.') % name
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
49
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
50 # Require password
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
51 else:
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 866
diff changeset
52 password = form.get('password', [None])[0]
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
53 if not password:
866
b270396abba9 say 'login failed', not 'wrong password' because it can have other reasons, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
54 error = _("Missing password. Please enter user name and password.")
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
55 else:
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
56 if not request.user.valid:
866
b270396abba9 say 'login failed', not 'wrong password' because it can have other reasons, too
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
57 error = _("Sorry, login failed.")
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
58
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
59 return self.page.send_page(request, msg=error)
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 866
diff changeset
60
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
61 else: # show login form
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
62 request.http_headers()
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 483
diff changeset
63 request.theme.send_title(_("Login"), pagename=self.pagename)
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
64 # Start content (important for RTL support)
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
65 request.write(request.formatter.startContent("content"))
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 866
diff changeset
66
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
67 request.write(userform.getLogin(request))
949
cbbde07e00c4 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 866
diff changeset
68
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
69 request.write(request.formatter.endContent())
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 483
diff changeset
70 request.theme.send_footer(self.pagename)
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
71 request.theme.send_closing_html()
483
a594780d5e64 Login macro, login/logout/UserPreferences actions
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
72