Exemple #1
0
def add(user_id):
    token = request.headers.get('x-auth-token', None)

    if not token:
        return Response(response='Unauthorized', status=401)

    if not _check_admin_token(token):
        return Response(response='Forbidden', status=403)

    payload = json.loads(request.data)

    user = model.User.find(user_id=user_id)
    if user:
        if 'pin' in payload:
            user.pin = payload['pin']
        if 'password' in payload:
            user.password = payload['password']

        user.token = str(uuid.uuid4())
        user.update_timestamp_and_attempts()
    else:
        user = model.User(user_id=user_id,
                          token=str(uuid.uuid4()),
                          pin=payload['pin'],
                          password=payload['password'])
        model.db.session.add(user)

    model.db.session.commit()
    return Response(response=user.token, status=200)
Exemple #2
0
 def create(changed=False):
     user = model.User(user_id=str(uuid.uuid4()),
                       token=str(uuid.uuid4()),
                       pin='1234',
                       password=str(uuid.uuid4()))
     model.db.session.add(user)
     model.db.session.commit()
     return user