Exemplo n.º 1
0
    def post(self):
        schema = LoginSchema()
        params = self.request.params
        try:
            data = schema.deserialize(params)
        except colander.Invalid as e:
            return {
                'errors': e.asdict(),
                'values': params,
            }

        user = UserManager.get_by_username(data.get('username'))
        if user and user.check_password(data.get('password')):
            headers = remember(self.request, user.username)
            return HTTPFound(location=self.request.route_path('home'), headers=headers)
        else:
            msg = u"Username or Password invalid."
            errors = {
                'username': msg,
                'password': msg,
            }
            return {
                'errors': errors,
                'values': params,
            }
Exemplo n.º 2
0
 def user(self):
     username = unauthenticated_userid(self)
     if username is not None:
         user = UserManager.get_by_username(username)
         return user