コード例 #1
0
ファイル: handlers.py プロジェクト: ac001/moe
    def post(self, **kwargs):
        if self.current_user is not None:
            # Don't allow existing users to access this page.
            return redirect(request.args.get('redirect', '/'))

        user = None
        error = None

        form, use_password = get_signup_form()
        username = form.data['username']
        email = form.data['email']

        kwargs = {'email': email}

        if use_password:
            kwargs['password'] = request.form.get('password')
            if kwargs['password'] != request.form.get('confirm_password'):
                error = True
                self.messages.add_form_error(_("Passwords didn't match."))

        if error is None:
            kwargs['is_admin'] = False
            if use_password:
                # Own authentication.
                auth_id = 'own|%s' % username
            else:
                current_user = users.get_current_user()
                if current_user is not None:
                    # App Engine authentication.
                    auth_id = 'gae|%s' % current_user.user_id()
                    kwargs['is_admin'] = users.is_current_user_admin()
                else:
                    # OpenId, Oauth, Facebook, Twitter or FriendFeed.
                    raise NotImplementedError()

            user = get_auth_system().create_user(username, auth_id, **kwargs)

            if user is None:
                self.messages.add_form_error(_('Username already exists. '
                    'Please try a different one.'))

        if user is not None:
            redirect_url = request.args.get('redirect', '/')
            if use_password:
                return redirect(create_login_url(redirect_url))
            else:
                return redirect(redirect_url)
        else:
            context = {
                'form': form,
                'messages': self.messages,
            }

            return self.render_response('users/signup.html', **context)
コード例 #2
0
ファイル: handlers.py プロジェクト: ac001/moe
    def pre_dispatch(self, handler):
        """Loads the current user and sets it as a handler property."""
        current_user = auth.get_current_user()

        handler.request.context.update({
            'current_user':     current_user,
            'login_url':        auth.create_login_url(request.url),
            'logout_url':       auth.create_logout_url('/'),
            'is_authenticated': auth.is_authenticated(),
        })

        setattr(handler, 'current_user', current_user)
コード例 #3
0
ファイル: handlers.py プロジェクト: ungood/brokin
 def dispatch(self, *args, **kwargs):
     """Sets up a lot of common context variables as well as session stuff."""
             
     if self.session and self.session.get('key') == None:
         self.session['key'] = key_generator.create_key()
     
     self.context = self.context or {}
     self.context['user']        = auth.get_current_user()
     self.context['signup_url']  = auth.create_signup_url(request.url)
     self.context['login_url']   = auth.create_login_url(request.url)
     self.context['logout_url']  = auth.create_logout_url(request.url)
     
     return RequestHandler.dispatch(self, *args, **kwargs)