()
登录
登录
登录
def login():
    """ 登录 """
    if request.json:
        data = request.json
    elif request.form:
        data = request.form
    else:
        data = request.data
        data = bytes.decode(data)
        data = json.loads(data)
    account = data.get('account')
    password = data.get('password')
    user = User.query.filter_by(account=account).first()
    if user is None:
        return jsonify({'msg': '账号错误或不存在', 'status': 0})
    elif not user.verify_password(password):
        return jsonify({'msg': '密码错误', 'status': 0})
    elif user.status == 0:
        return jsonify({'msg': '该账号被冻结', 'status': 0})
    else:
        login_user(user, True)
        token = user.generate_reset_token()
        token = bytes.decode(token)
        return jsonify({'msg': '登录成功', 'status': 1, 'token': token,
                        'name': user.name, 'userId': user.id, 'roles': str(user.role_id)})
def login ( ) : if request . json : data = request . json elif request . form : data = request . form else : data = request . data data = bytes . decode ( data ) data = json . loads ( data ) account = data . get ( 'account' ) password = data . get ( 'password' ) user = User . query . filter_by ( account = account ) . first ( ) if user is None : return jsonify ( { 'msg' : '账号错误或不存在', 'status': 0}) elif not user . verify_password ( password ) : return jsonify ( { 'msg' : '密码错误', 'statu s : 0}) elif user . status == 0 : return jsonify ( { 'msg' : '该账号被冻结', 'status':  0 ) else : login_user ( user , True ) token = user . generate_reset_token ( ) token = bytes . decode ( token ) return jsonify ( { 'msg' : '登录成功', 'statu s : 1, 'to k n '  token, 'name' : user . name , 'userId' : user . id , 'roles' : str ( user . role_id ) } )