Beispiel #1
0
def login_submit():
    """
        进行登录
    """
    log.info("login_submit")
    user = request.forms.get('user')
    user = db.user.find_one({'$or':[{'name':user},{'schoolid':user}]})
    if checkpassword(request.forms.get('pass'),user['passwd']):
        response.set_cookie('user',user['name'],secret='chermong')
        return redirect(chermongapp+'index') 
    else:
        return login_form()
Beispiel #2
0
def changepasswd_form():
    """
        修改密码
    """
    log.info("changepasswd_form")
    user = request.get_cookie('user',secret="chermong")
    user = db.user.find_one({'name':user})
    if checkpassword(request.forms.get('oldpass'),user['passwd']):
        if request.forms.get('newpass') == request.forms.get('repeatpass'):
            db.user.update({'name':user['name']},{'$set':{'passwd':encrypt(request.forms.get('newpass'))}})#注意mongodb中update方法的使用
            response.delete_cookie(key='user',secret='chermong')
            return jinja2_template('login.html')
        else:
            errormsg = u"两次输入密码不同,请重新输入!"
            return jinja2_template('changepasswd.html',user = user,app = chermongapp,error_repeate=errormsg)
    else:
        errormsg = u"密码不正确!"
        return jinja2_template('changepasswd.html',user = user,app = chermongapp,error_oldpass=errormsg)