def post(self): data = request.json current_user = UserModel.find_by_login(data.get('login')) if not current_user: abort( 401, 'El usuario con login {} no existe'.format(data.get('login'))) if UserModel.verify_hash(data['password'], current_user.password): if not current_user.activated: abort(401, 'El usuario no está activado') expires = timedelta(days=1) created_access_token = create_access_token(identity=current_user, expires_delta=expires) ## db = firestore.client() ## doc_ref = db.collection(u'ingreso_{}'.format(current_user.login)).document( ## datetime.now().strftime("%Y-%m-%d %H:%M:%S")) ## doc_ref.set({ ## u'usuario': current_user.login, ## u'fecha_entrada': datetime.now().strftime("%Y-%m-%d %H:%M:%S") ## }) return {'id_token': created_access_token}, 201 else: abort(401, 'Credenciales incorrectas')
def put(self): user_login = get_jwt_identity() current_user = UserModel.find_by_login(user_login) if not current_user: abort(401, 'El usuario con login {} no existe'.format(user_login)) data = change_pss_parser.parse_args() if not UserModel.verify_hash(data['old_password'], current_user.password): abort(401, 'El password anterior no coincide') current_user.password = UserModel.generate_hash(data['new_password']) current_user.save_to_db() return {'message': 'El password se ha cambiado correctamente'}