Пример #1
0
 def post(self):
     _user_schema = UserSchema(only=(
         "email",
         "password",
     ))
     data = request.get_json()
     args = _user_schema.load(data)
     user = Users.query.filter_by(email=args['email']).first()
     if user and user.check_pass(args['password']):
         if user.confirmation.activated:
             access_token = create_access_token(identity=user.id,
                                                fresh=True)
             refresh_token = create_refresh_token(identity=user.id)
             # encode jti token to store database redis
             access_jti = get_jti(encoded_token=access_token)
             refresh_jti = get_jti(encoded_token=refresh_token)
             # store to database redis
             revoked_store.set(access_jti, 'false', _ACCESS_EXPIRES)
             revoked_store.set(refresh_jti, 'false', _REFRESH_EXPIRES)
             return {
                 "access_token": access_token,
                 "refresh_token": refresh_token,
                 "username": user.username
             }, 200
         return {"message": "Check your email to activated user."}, 400
     return {"message": "Invalid credential"}, 400
Пример #2
0
 def put(self):
     user = Users.query.get(get_jwt_identity())
     user_schema = UserSchema(only=(
         "username",
         "company_name",
         "company_site",
         "position",
     ))
     data = request.get_json()
     args = user_schema.load(data)
     user.update_profile(**args)
     user.change_update_time()
     user.save_to_db()
     return {"message": "Profile successfully updated."}, 200
Пример #3
0
    def post(self):
        _user_schema = UserSchema(only=("email", ))
        data = request.get_json()
        args = _user_schema.load(data)
        user = Users.query.filter_by(email=args['email']).first_or_404(
            description='Email not found.')
        if user.confirmation.activated:
            return {"message": "Your account already activated."}, 200

        if user.confirmation.resend_expired is None or user.confirmation.resend_is_expired:
            try:
                user.confirmation.send_email_confirm()
                user.confirmation.change_expired()
                user.confirmation.generate_resend_expired()
                user.confirmation.save_to_db()
                return {"message": "Email confirmation has send"}, 200
            except MailSmtpException as err:
                return {"error": str(err)}, 500
        return {"error": "You can try 5 minute later"}, 400
Пример #4
0
 def get(self):
     _user_schema = UserSchema(exclude=("password", ))
     user = Users.query.options(orm.joinedload('jobs')).get(
         get_jwt_identity())
     return _user_schema.dump(user), 200