info/modules/passport/views.py
def login():
    """
    login api
    need mobile and passworld
    """
    # get parmas and detemine if there is a value
    data = request.json
    mobile = data.get('mobile')
    password = data.get('password')

    # verify params
    if not all([mobile, password]):
        return jsonify(error=RET.PARAMERR, errmsg='参数不全')

    # find user from database of user table
    try:
        user = User.query.filter_by(mobile=mobile).first()
    except Exception as e:
        current_app.logger.info(e)
        return jsonify(error=RET.DATAERR, errmsg='用户查询错误')
    # if not have user
    if not user:
        return jsonify(error=RET.DATAEXIST, errmsg='用户不存在')

    # verify password
    if not user.check_passowrd(password):
        return jsonify(error=RET.PWDERR, errmsg='用户名或密码错误')

    # login success save user infomations in session
    session['user_id'] = user.id
    session['nick_name'] = user.nick_name
    session['mobile'] = user.mobile
    # recording last login time
    user.last_login = datetime.now()
    # submit user infomations update
    try:
        db.session.commit()
    except Exception as e:
        current_app.error(e)
        return jsonify(error=RET.DATAERR, errmsg='用户数据更新错误')

    return jsonify(error=RET.OK, errmsg='ok')

    login api
    need mobile and passworld
    
login api
need mobile and passworld
login api need mobile and passworld
def login():
    data = request.json
    mobile = data.get('mobile')
    password = data.get('password')
    if not all([mobile, password]):
        return jsonify(error=RET.PARAMERR, errmsg='参数不全')
    try:
        user = User.query.filter_by(mobile=mobile).first()
    except Exception as e:
        current_app.logger.info(e)
        return jsonify(error=RET.DATAERR, errmsg='用户查询错误')
    if not user:
        return jsonify(error=RET.DATAEXIST, errmsg='用户不存在')
    if not user.check_passowrd(password):
        return jsonify(error=RET.PWDERR, errmsg='用户名或密码错误')
    session['user_id'] = user.id
    session['nick_name'] = user.nick_name
    session['mobile'] = user.mobile
    user.last_login = datetime.now()
    try:
        db.session.commit()
    except Exception as e:
        current_app.error(e)
        return jsonify(error=RET.DATAERR, errmsg='用户数据更新错误')
    return jsonify(error=RET.OK, errmsg='ok')
def login ( ) : data = request . json mobile = data . get ( 'mobile' ) password = data . get ( 'password' ) if not all ( [ mobile , password ] ) : return jsonify ( error = RET . PARAMERR , errmsg = '参数不全') try : user = User . query . filter_by ( mobile = mobile ) . first ( ) except Exception as e : current_app . logger . info ( e ) return jsonify ( error = RET . DATAERR , errmsg = '用户查询错误') if not user : return jsonify ( error = RET . DATAEXIST , errmsg = '用户不存在') if not user . check_passowrd ( password ) : return jsonify ( error = RET . PWDERR , errmsg = '用户名或密码错误') session [ 'user_id' ] = user . id session [ 'nick_name' ] = user . nick_name session [ 'mobile' ] = user . mobile user . last_login = datetime . now ( ) try : db . session . commit ( ) except Exception as e : current_app . error ( e ) return jsonify ( error = RET . DATAERR , errmsg = '用户数据更新错误') return jsonify ( error = RET . OK , errmsg = 'ok' )
login api
need mobile and passworld
login api need mobile and passworld
"""
    login api
    need mobile and passworld
    """ # get parmas and detemine if there is a value # verify params # find user from database of user table # if not have user # verify password # login success save user infomations in session # recording last login time # submit user infomations update