Exemplo n.º 1
0
def get_access_token(result):
    data=request.get_json()
    challenge=data['challenge']
    account=data['mobile']
    pass_code=data['pass_code']
    user=User.query.filter_by(mobile=account).first()
    if not user:
        result['code']=1
        result['msg']="mobile is not exist"
        return 
    m=md5()
    m.update(user.passwd+challenge)
    check_code=m.hexdigest()
    if check_code!=pass_code:
        result['code']=1
        result['msg']="password is not correct"
        return
    token=Token.query.filter_by(user_id=user.id).first()
    if token:
        access_token=token.token
    else:
        access_token=user_service.get_access_token()
        token=Token(challenge=challenge,user_id=user.id,token=access_token,expires=-1)
        db.session.add(token)
        db.session.commit()
    result['access_token']=access_token
Exemplo n.º 2
0
def sign_up(result):
    data=request.get_json()
    mobile=data['mobile']
    passwd=data['pwd']
    sms_code=data['sms_code']
    user=User.query.filter_by(mobile=mobile).first()
    if user:
        result['code']=1
        result['msg']='手机号码已经存在'
        return 
    else:
        if sms_code==sms_code_cache.get(mobile):
            user=User(mobile=mobile,passwd=passwd)
            db.session.add(user)
            db.session.commit()
            access_token=user_service.get_access_token()
            token=Token(challenge=user_service.get_access_token(),user_id=user.id,token=access_token,expires=-1)
            db.session.add(token)
            db.session.commit()
            result['access_token']=access_token
            result['expires']=-1
        else:
            result['code']=1
            result['msg']='验证码不正确'