push access token if registered
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2020-12-06 00:12:57 +01:00
parent 308184f4cf
commit 2a1be04fb3
1 changed files with 11 additions and 6 deletions

View File

@ -55,8 +55,10 @@ class SignupApi(Resource):
current_app.logger.warning(e)
abort(503, "user already exists")
expires = datetime.timedelta(days=7)
access_token = create_access_token(identity=str(user.name), expires_delta=expires)
db.session.commit()
return self.usermetadataschema.dump(user), 200
return {'token': access_token}, 200
class LoginApi(Resource):
@ -75,11 +77,14 @@ class LoginApi(Resource):
except Exception as e:
current_app.logger.warning(e)
abort(417, INVALID_JSON_SCHEMA_MSG)
user = VideonUser.query.filter_by(name=userobj['name']).first_or_404()
authorized = user.check_password(userobj['password'])
if not authorized:
abort(401, "username or password incorrect")
try:
user = VideonUser.query.filter_by(name=userobj['name']).first()
authorized = user.check_password(userobj['password'])
if not authorized:
abort(401, "username or password incorrect")
except Exception as e:
current_app.logger.info(e)
abort(401, "unauthorized")
try:
user.last_logon = datetime.datetime.now()