Ejemplo n.º 1
0
def login():
    if g.token_used:
        bad_request('must use password login')
    return jsonify({
        'token': g.current_user.generate_auth_token().encode('ascii'),
        'profile': {
            'name': g.current_user.name
        }
    })
Ejemplo n.º 2
0
 def wrapped(*args, **kwargs):
     s = Serializer(current_app.config['SECRET_KEY'])
     token = request.headers.get('eD-Token', '')
     if not token:
         return bad_request('Missing token')
     try:
         data = s.loads(token)
     except:
         return bad_request('Token incorrect')
     g.session_data = data
     return f(*args, **kwargs)
Ejemplo n.º 3
0
def register():
    userinfo=request.json
    if userinfo['userName'] == '' or userinfo['userEmail'] == '' or userinfo['passWord'] == '':
        return bad_request('message was empty')
    user_by_email = User.query.filter_by(userEmail=userinfo['userEmail']).first()
    user_by_name = User.query.filter_by(userName=userinfo['userName']).first()
    if user_by_name is not None:
        return NotAccept('userName was aleady exist')
    if user_by_email is not None:
        return ResourceConflict('email was aleady exist')
    u=User(id=getPrimaryKeyId('isUser'), name='jxnugo_'+str(getPrimaryKeyId('isUser')), userName=userinfo['userName'], userEmail=userinfo['userEmail'],passWord=userinfo['passWord'])
    db.session.add(u)
    db.session.commit()
    token=u.generate_confirmation_token()
    send_email(u.userEmail,'激活你的账户',
                   'auth/email/confirm', User=u, token=token
                   )
    response=jsonify({"registerStatus":"successful"})
    response.status_code=200
    return response
Ejemplo n.º 4
0
def bad_request_error(e):
    return bad_request('invalid request')
Ejemplo n.º 5
0
def validation_error(e):
    return bad_request(str(e))
Ejemplo n.º 6
0
def validation_error(e):
    return bad_request(e.args[0])