コード例 #1
0
ファイル: web_admin_api.py プロジェクト: agualis/AOS2012
def init_app(request):
    if request.method == 'GET':
        User.create_admin('admin', 'aos').put()
        Room.init_rooms()
        if not Talk.all().count(1) > 0:
            talk = Talk(title = 'Android', session=1)
            talk.set_room(Room.get_rooms()[0])
            talk.put()
            talk = Talk(title = 'Kanban', session=5)
            talk.set_room(Room.get_rooms()[1])
            talk.put()
        if not Attendant.all().count(1) > 0:
            bill = Attendant.create('Bill', 'Gates', '*****@*****.**', 'Zaragoza', False)
            bill.twitter_id = 'fbgblog'
            bill.set_as_speaker()
            bill.put()
            richard = Attendant.create('Richard', 'Stallman', '*****@*****.**', 'Pamplona', True)
            richard.twitter_id = 'GNUplusLINUX'
            richard.set_as_speaker()
            richard.put()
        return HttpResponse("App ready to rumble...", mimetype="text/plain")
コード例 #2
0
ファイル: authentication.py プロジェクト: agualis/AOS2012
def login(request, return_url='/'):
    '''
        When it's first called (using GET) it creates a new FormToken in cache and redirects to login page
        Once it's called again  (using POST with an AJAX request) it validates the token, user and pass of the request. 
    '''
    if request.method == 'GET':
        request.session.pop('user', None)
        return direct_to_template(request, 'login.html', {'token': tokens.get_form_token(request)})
    elif request.method == 'POST':
        try:
            if not request.is_ajax():
                request.session.delete()
                return HttpResponseForbidden()
            token = request.POST.get('token')
            tokens.validate(request, token)
            user_id = request.POST.get('user_id')[:20]
            user = User.by_user_id(user_id) if user_id else None
            if user:
                passhash = request.POST.get('passhash')
                if passhash and (sha(token + user.passhash).hexdigest() == passhash):
                    request.session['user'] = user
                    if user.has_role(Role.ADMIN) and (not return_url or return_url=='/'):
                        return_url = '/timetable'
                    else :
                        return_url = return_url or '/'
                    return JsonResponse({'return_url': return_url})
                else:

                    return JsonResponse({'error': ('passphrase', 'Clave incorrecta'),
                                                    'token': tokens.get_form_token(request),
                                        })
            else:
                message = 'Usuario o password incorrectos. Por favor inténtelo de nuevo.'
                return JsonResponse({'error': ('uid', message.decode('utf-8')),
                                                'token': tokens.get_form_token(request),
                                    })
        except tokens.InvalidToken, t:
            logging.warning(t)
            return JsonResponse({'return_url': '/login%s' % return_url or ''})
        except Exception, e:
            logging.exception(e)
            return HttpResponseServerError()
コード例 #3
0
ファイル: attendant_model.py プロジェクト: agualis/AOS2012
 def create_user(self):
     user = User.create_web_user(self.email, 'patata')
     self.user = user
     return user