def login(): message='' data={ 'cookies':request.cookies, 'base_url':request.base_url } if request.method=='POST': phone=request.form.get('phone') passwd=request.form.get('passwd') login_user=User.query.filter(User.phone==phone,\ User.auth_key==crypt.pwd(passwd)).one() if login_user: #登陆成功,生成token token=uuid.uuid4().hex resp=redirect('/') resp.set_cookie('token',token,\ expires=(datetime.now()+timedelta(days=3))) #将token添加redis,token-user_id cache.save_token(token,login_user.id) return resp else: message='not user' return render_template('user/login.html',**data,msg=message)
def login(): if request.method == 'POST': name = request.form.get('name', None) auth_key = request.form.get('auth_key', None) if all((name, auth_key)): login_user = is_login_verity(name, auth_key) if login_user: # 登录成功 生成token token = uuid.uuid4().hex # 将token添加到redis,token->user_id cache.save_token(token, login_user.id) return jsonify({ 'code': 200, 'token': token, 'msg': USER_CONFIG.get(200) }) return jsonify({'code': 404, 'msg': USER_CONFIG.get(404)}) return jsonify({"code": 10001, "msg": USER_CONFIG.get(10001)}) return render_template('/user/login.html')
def login(): message = '' if request.method == 'POST': phone = request.form.get('phone') passwd = request.form.get('passwd') login_user = User.query.filter(User.phone == phone, User.auth_key == crypt.pwd(passwd)).one() if login_user: # 登录成功 # 生成token token = uuid.uuid4().hex resp = redirect('/') resp.set_cookie(('token', token, expires=(datetime.now()+timedelta(days=3))), ('role',login_user.roles.name,expires = (datetime.now()+timedelta(days=3))), ('qx',login_user.roles.qxs.name,expires = (datetime.now()+timedelta(days=3))), )) # 将token添加到redis, token-user_id cache.save_token(token, login_user.id) return resp
def login(): message = '' if request.method == 'POST': phone = request.form.get('phone') passwd = request.form.get('passwd') login_user = User.query.filter(User.phone == phone, User.auth_key == crypt.pwd(passwd)).one() if login_user: # 登入成功 # 生成token token = uuid.uuid4().hex resp = redirect('/') resp.set_cookie('token', token, expires=(datetime.now() + timedelta(days=3))) # 将token添加到redis中, token_user_id cache.save_token(token, login_user.id) return resp else: message = '查询此用户' return render_template('user/login.html', msg=message)
def login(): massege = None if request.method == 'POST': phone = request.form.get('phone') password = request.form.get('password') try: login_user = User.query.filter(User.phone == phone, User.auth_key == pwd(password)).one() except: login_user = None if login_user: # 登陆成功 # 生成token token = uuid.uuid4().hex resp = redirect('/') resp.set_cookie('token', token, expires=(datetime.now() + timedelta(days=3))) cache.save_token(token, login_user.id) # 将token添加到redis,token-user_id return resp else: # 登陆失败 massege = '查无此用户' return render_template('user/login.html', msg=massege)
def login(): message = '' if request.method == 'POST': nick_name = request.form.get('nick_name') passwd = request.form.get('passwd') # 去数据库查询是否有此用户 login_user = User.query.filter(User.nick_name == nick_name, User.auth_key == passwd).first() if login_user: # 登录成功 # 生成token token = uuid.uuid4().hex resp = redirect('/') resp.set_cookie('token', token, expires=(datetime.now() + timedelta(days=3))) # 将token添加到redis, token-user_id cache.save_token(token, login_user.id) return resp else: message = '查无此用户' return render_template('user/login.html', msg=message)