예제 #1
0
 def login(session, *args):
     try:
         attributes = args[0]
         username = attributes['username']
         password = attributes['password']
         user = session.query(User).filter(
             User.username == username).one()
         if is_password_valid(user.password, password):
             exp = time() + 24 * 3600
             payload = {
                 'user_id': user.id,
                 'username': user.username,
                 'firstName': user.firstName,
                 'lastName': user.lastName,
                 'email': user.email,
                 'role': user.role.serialize(),
                 'exp': exp
             }
             return {
                 "token": jwt.encode(
                     payload, VarConfig.get()['password'],
                     algorithm='HS256').decode('utf-8')
             }
         else:
             raise Unauthorized
     except Exception as e:
         info_logger.error(e)
         raise Unauthorized('Wrong credentials')
예제 #2
0
    def new_function(*args, **kwargs):
        try:
            if authorization_function:
                authorization_function(authorization, resource_id)

            response = old_function(*args, **kwargs)
            if response is None:
                return '', 204
            if isinstance(response, (dict, list)):
                return jsonify(response)
            return response

        except LoginError:
            return jsonify({'message': 'unauthorized'}), 401

        except AuthError:
            return jsonify({'message': 'access denied'}), 403

        except (NotFound, sqlalchemy.orm.exc.NoResultFound):
            return jsonify({'message': 'no result found'}), 404

        except sqlalchemy.exc.IntegrityError:
            return jsonify({'message': 'integrity error'}), 422

        except FormatError:
            return jsonify({'message': 'incorrect file'}), 423

        except EmailError:
            return jsonify({'message': 'mail error'}), 502

        except Exception as e:
            print(e)
            info_logger.error(e)

        return jsonify({'message': 'unexpected error'}), 500
예제 #3
0
def save_file(filename, file):
    try:
        extension = get_extension(file.filename)
        if extension in ALLOWED_EXTENSIONS:
            location = str(filename) + '.' + extension
            file.save(os.path.join(UPLOAD_FOLDER, location))
            return location
    except Exception as e:
        info_logger.error(e)
        return None
 def new_function(*args):
     session = Session()
     response = None
     try:
         obj = old_function(session, *args)
         response = serialize(obj)
     except Exception as e:
         info_logger.error(e)
         raise e
     finally:
         session.close()
     return response
예제 #5
0
    def update_temp_pass(session, *args):
        member_email = args[0].pop('email', None)
        info_logger.error(member_email)

        member = session.query(Member) \
            .filter(Member.email == member_email).one()

        if not member:
            raise NotFound
        else:
            temp_password = member.user.update_temp_pass()
            session.add(member)
            Email.send_reset_email(member, temp_password)