Back to index

moin  1.9.0~rc2
login.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - login action
00004 
00005     The real login is done in MoinMoin.request.
00006     Here is only some user notification in case something went wrong.
00007 
00008     @copyright: 2005-2006 Radomirs Cirskis <nad2000@gmail.com>,
00009                 2006 MoinMoin:ThomasWaldmann
00010     @license: GNU GPL, see COPYING for details.
00011 """
00012 
00013 from MoinMoin import userform
00014 from MoinMoin.Page import Page
00015 from MoinMoin.widget import html
00016 
00017 def execute(pagename, request):
00018     return LoginHandler(pagename, request).handle()
00019 
00020 class LoginHandler:
00021     def __init__(self, pagename, request):
00022         self.request = request
00023         self._ = request.getText
00024         self.cfg = request.cfg
00025         self.pagename = pagename
00026         self.page = Page(request, pagename)
00027 
00028     def handle_multistage(self):
00029         """Handle a multistage request.
00030 
00031         If the auth handler wants a multistage request, we
00032         now set up the login form for that.
00033         """
00034         _ = self._
00035         request = self.request
00036         form = html.FORM(method='POST', name='logincontinue', action=self.pagename)
00037         form.append(html.INPUT(type='hidden', name='login', value='login'))
00038         form.append(html.INPUT(type='hidden', name='stage',
00039                                value=request._login_multistage_name))
00040 
00041         request.theme.send_title(_("Login"), pagename=self.pagename)
00042         # Start content (important for RTL support)
00043         request.write(request.formatter.startContent("content"))
00044 
00045         extra = request._login_multistage(request, form)
00046         request.write(unicode(form))
00047         if extra:
00048             request.write(extra)
00049 
00050         request.write(request.formatter.endContent())
00051         request.theme.send_footer(self.pagename)
00052         request.theme.send_closing_html()
00053 
00054     def handle(self):
00055         _ = self._
00056         request = self.request
00057         form = request.values
00058 
00059         error = None
00060 
00061         islogin = form.get('login', '')
00062 
00063         if islogin: # user pressed login button
00064             if request._login_multistage:
00065                 return self.handle_multistage()
00066             if hasattr(request, '_login_messages'):
00067                 for msg in request._login_messages:
00068                     request.theme.add_msg(msg, "error")
00069             return self.page.send_page()
00070 
00071         else: # show login form
00072             request.theme.send_title(_("Login"), pagename=self.pagename)
00073             # Start content (important for RTL support)
00074             request.write(request.formatter.startContent("content"))
00075 
00076             request.write(userform.getLogin(request))
00077 
00078             request.write(request.formatter.endContent())
00079             request.theme.send_footer(self.pagename)
00080             request.theme.send_closing_html()
00081