diff --git a/src/resources.py b/src/resources.py index 203d5d8..9376e00 100644 --- a/src/resources.py +++ b/src/resources.py @@ -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()