Пример #1
0
def uname_exists(request):
    if request.method == 'POST':
        valkey = request.params['type']
        
        if valkey == 'username':
            uname = request.params['username']
            uCount = User.objects(username=uname).count()
            
        if valkey == 'email':
            email = request.params['email']
            uCount = User.objects(email=email).count()
        
        if uCount > 0:
            v = False
            return {'valid': v}
        
        v = True
        return {'valid': v}
Пример #2
0
def register_post(request):
    if request.method == 'POST':
        username    = request.params['username']
        password    = request.params['password']
        pass_match  = request.params['passwordmatch']
        email       = request.params['email']
        language    = request.params.get('language')

        if password != pass_match:
            return {'code': u'KO', 'msg': u'Passwords not matching!'}

        u = User(username=username ,email=email, role = 'reg')
        u.setPass(password)
        
        u.save()
        # add the user itself to the one he follows
        u.addFollowing(u.id)
        
        return {'code': u'OK', 'msg': u'Account created', 'redirect': route_url('login_rt', request)}
Пример #3
0
def login_post(request):
    main_view = route_url('map_home', request)
    came_from = request.params.get('came_from', main_view)

    print 'came_from :[%s]' %came_from
    print 'main_view :[%s]' %main_view

    post_data = request.POST
    if 'submit' in post_data:
        if request.session.get_csrf_token() == post_data['_csrf']:

            username = post_data['username']
            password = post_data['password']

            print 'login: '******'%s %s' %(username, password)

            if  User.check_password(username, password):
                headers = remember(request, username)
                request.session.flash(u'Logged in successfully.')
                ret = { 'code':u'OK', 'msg' : u'Logged in successfully.' }
                if came_from != '':
                    ret['redirect'] = came_from
                print 'login succesful'
                return Response(json.dumps(ret), headerlist = headers)
            else:
                return {
                    'code' : u'KO',
                    'msg' : u'Could not login, username or password wrong.'
                }
                print 'Could not login, username or password wrong'
        else:
            request.session.flash(u'Bad request')
            ret = { 'code':u'KO', 'msg' : u'Bad request.' }
            return Response(json.dumps(ret))

    request.session.flash(u'Failed to login.')
    ret = { 'code':u'KO', 'msg': u'Failed to login.' }
    return Response(json.dumps(ret))