예제 #1
0
파일: user.py 프로젝트: notedit/missing
def signup():
    if authutil.is_logined(request):
        return redirect('/')

    form = SignupForm(next=request.values.get('next'))

    if form.validate_on_submit():
        
        username = form.username.data.encode('utf-8')
        password = form.password.data.encode('utf-8')
        email = form.email.data.encode('utf-8')

        
        try:
            user = backend.add_user(username,email,password)
        except BackendError,ex:
            logging.info(traceback.format_exc())
            flash('用户注册失败,请稍后再试','error')
            return render_template('signup.html',form=form)

        next_url = form.next.data

        if not next_url or next_url == request.path:
            next_url = '/'

        return redirect(next_url)
예제 #2
0
def signup():
    if authutil.is_logined(request):
        return redirect('/')

    form = SignupForm(next=request.values.get('next'))

    if form.validate_on_submit():

        username = form.username.data.encode('utf-8')
        password = form.password.data.encode('utf-8')
        email = form.email.data.encode('utf-8')

        try:
            user = backend.add_user(username, email, password)
        except BackendError, ex:
            logging.info(traceback.format_exc())
            flash('用户注册失败,请稍后再试', 'error')
            return render_template('signup.html', form=form)

        next_url = form.next.data

        if not next_url or next_url == request.path:
            next_url = '/'

        return redirect(next_url)
예제 #3
0
def login():
    if authutil.is_logined(request):
        return redirect('/')

    form = LoginForm(email=request.values.get('email', ''),
                     password=request.values.get('password', ''))

    if form.validate_on_submit():
        email = form.email.data.encode('utf-8')
        password = form.password.data.encode('utf-8')

        ret, user = backend.auth_user(email, password)
        if ret:
            next_url = form.next.data
            if not next_url or next_url == request.path:
                next_url = '/'
            resp = redirect(next_url)
            timeout = 24 * 3600 * 180 if form.remember.data else None
            authutil.set_logined(request,
                                 resp,
                                 str(user['id']),
                                 timeout=timeout)
            return resp

        flash(u'用户名或者密码错误,请重试', 'error')

    return render_template('site/login.html', form=form)
예제 #4
0
 def cookie_auth():
     if request.cookies.get('is_logined'):
         if authutil.is_logined(request):
             max_age = 3600*24*30*6
             expires_time = int(time.time()) + max_age
             expires = strutil.cookie_date(expires_time) 
             g.user = backend.get_user(int(request.cookie.get('ukey')))
             @after_this_request
             def set_cookie(response):
                 response.set_cookie('is_logined',
                                     'True',
                                     max_age=max_age,
                                     expires=expires,
                                     path='/')
                 return response
         else:
             g.user = {}
             @after_this_request
             def delete_cookie(response):
                 response.delete_cookie('is_logined')
                 return response
     else:
         g.user = {}
예제 #5
0
파일: user.py 프로젝트: notedit/missing
def login():
    if authutil.is_logined(request):
        return redirect('/')

    form = LoginForm(email=request.values.get('email',''),
                    password=request.values.get('password',''))

    if form.validate_on_submit():
        email = form.email.data.encode('utf-8')
        password = form.password.data.encode('utf-8')

        ret,user = backend.auth_user(email,password)
        if ret:
            next_url = form.next.data
            if not next_url or next_url == request.path:
                next_url = '/'
            resp = redirect(next_url)
            timeout = 24 * 3600 * 180 if form.remember.data else None
            authutil.set_logined(request,resp,str(user['id']),timeout=timeout)
            return resp

        flash(u'用户名或者密码错误,请重试','error')

    return render_template('site/login.html',form=form)