コード例 #1
0
    def post(self):
        data = registration_parser.parse_args()
        msisdn = data['msisdn']
        if is_msisdn_valid(msisdn):

            current_user = UserModel.find_by_msisdn(msisdn)
            if current_user:
                if current_user.password_status == PASSWORD_STATUS['USED']:
                    password = gen_password()
                    current_user.password = UserModel.generate_hash(password)
                    current_user.password_status = PASSWORD_STATUS['NEW']
                    current_user.update_data()

                    password_history_note = PasswordHistoryModel(
                        msisdn=current_user.msisdn,
                        password=current_user.password)
                    password_history_note.add()

                    send_password_sms_to_user(password, msisdn)
                    return {
                        'message':
                        'New password for MSISDN {} was created'.format(msisdn)
                    }, 200

                if current_user.password_status == PASSWORD_STATUS['NEW']:
                    password = gen_password()
                    current_user.password = UserModel.generate_hash(password)
                    current_user.update_data()

                    password_history_note = PasswordHistoryModel(
                        msisdn=current_user.msisdn,
                        password=current_user.password)
                    password_history_note.add()

                    send_password_sms_to_user(password, msisdn)
                    return {
                        'message':
                        'New password for MSISDN {} was created'.format(msisdn)
                    }, 200

            else:
                password = gen_password()

                new_user = UserModel(
                    msisdn=msisdn, password=UserModel.generate_hash(password))
                password_history_note = PasswordHistoryModel(
                    msisdn=new_user.msisdn, password=new_user.password)

                try:
                    new_user.save_to_db()
                    password_history_note.add()
                    send_password_sms_to_user(password, msisdn)
                    return {
                        'message':
                        'New password for MSISDN {} was created'.format(msisdn)
                    }, 200
                except:
                    return {'message': 'Internal error'}, 500
        else:
            return {'message': 'Wrong format for MSISDN'}, 400
コード例 #2
0
    def post(self):
        data = request.get_json()
        user = user_schema.load(data)
        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists.'.format(data['username'])
            }

        new_user = UserModel(username=user.data['username'],
                             password=UserModel.generate_hash(
                                 user.data['password']),
                             firstName=user.data['firstName'],
                             lastName=user.data['lastName'],
                             email=user.data['email'],
                             phoneNumber=user.data['phoneNumber'],
                             proPicUrl=user.data['proPicUrl'],
                             organization=user.data['organization'])

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'User {} was created.'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Something went wrong.'}, 500
コード例 #3
0
    def post(self):
        data = parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }

        new_user = UserModel(id=random.randint(0, 100000000),
                             username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']))
        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except Exception as e:
            return {
                'message': 'Something went terribly wrong\n {}!'.format(e)
            }, 500

        return data
コード例 #4
0
ファイル: resources.py プロジェクト: kyych/kNotes
    def post(self):
        data = parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']))
        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            # return {
            #     'message':'User {} was created'.format(data['username']),
            #     'access_token':access_token,
            #     'refresh_token':refresh_token
            # }
            resp = make_response(redirect(url_for('dashboard')))
            resp.set_cookie('access_token', access_token, httponly=True)
            resp.set_cookie('refresh_token', refresh_token, httponly=True)
            session['username'] = data['username']
            #return redirect(url_for('dashboard', messages="test"))
            return resp
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #5
0
    def post(self):
        data = parser.parse_args()
        username = data['username']

        # Checking that user is already exist or not
        if UserModel.find_by_username(username):
            return {'message': f'User {username} already exists'}

        # create new user
        new_user = UserModel(username=username,
                             password=UserModel.generate_hash(
                                 data['password']))

        try:
            # Saving user in DB and Generating Access and Refresh token
            new_user.save_to_db()
            access_token = create_access_token(identity=username)
            refresh_token = create_refresh_token(identity=username)
            return {
                'message': f'User {username} was created',
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #6
0
ファイル: resources.py プロジェクト: Ashhuu/FlaskApp
    def post(self, form):
        data = form
        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }
        '''new_user = UserModel(
            username=data['username'],
            password=UserModel.generate_hash(data['password'])
        )'''
        add = UserModel(fname=data['fname'],
                        email=data['email'],
                        username=data['username'],
                        password=UserModel.generate_hash(data['password']),
                        phone=data['phone'],
                        city=data['city'],
                        country=data['country'],
                        state=data['state'])

        try:
            add.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #7
0
    def post(self):
        data = parserRegistration.parse_args()

        #El resultado que devuelve la clase se analiza y compara con la condicional if, si es true, 
        #retorna un mensaje de un correo existente
        if UserModel.find_by_Email(data['email']):
            return {
                'message': 'The user with the mail {} already exists'.format(data['email'])
            }
        
        #Se crea un objeto de un nuevo usuario
        newUser = UserModel(
            id = UserModel.generate_id(),
            email = data['email'],
            username = data['username'],
            password = UserModel.generate_hash(data['password']),
            name = data['name']
        )

        #Se crean tokens de acceso y de refresh con el email
        accessToken = create_access_token(identity =  data['email'])
        refreshToken = create_refresh_token(identity =  data['email'])

        #El manejador de excepciones mostrará un mensaje de que un usuario ha sido creado, por lo 
        #contrario, mostrará que algo ha salido mal
        try:
            newUser.create_user()
            return {
                'message': 'User {} was created'.format(data['email']),
                'token': accessToken,
                'refreshToken': refreshToken,
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #8
0
ファイル: resources.py プロジェクト: yssam-mtibaa/dnsFookup
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', help = 'This field cannot be blank', required = True)
        parser.add_argument('password', help = 'This field cannot be blank', required = True)
        data = parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {'message': 'User already exists', 'error': True}, 500
        elif len(data['password']) <= 7:
            return {'message': 'Password has to be at least 8 chars long', 'error': True}, 500
        new_user = UserModel(
            username = data['username'],
            password = UserModel.generate_hash(data['password'])
        )

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity = data['username'])
            #refresh_token = create_refresh_token(identity = data['username'])
            return {
                'name': data['username'],
                'access_token': access_token,
                #'refresh_token': refresh_token
                }
        except:
            return {'message': 'Something went wrong', 'error': True}, 500
コード例 #9
0
    def post(self):
        data = parser.parse_args()
        # check in db if user already exist
        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }

        # add user to database
        new_user = UserModel(id=data['id'],
                             username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']))
        # try to save to database
        try:
            new_user.save_to_db()
            # create jwt tokens to return to user
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'User {} was created'.format(data['username']),
                'id': data['id'],
                'username': data['username  '],
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        # handle exceptions
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #10
0
    def post(self):
        data = parser.parse_args()
        if (UserModel.find_by_username(data['username'])):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             nombre=data['nombre'],
                             telefono=data['telefono'],
                             id_tipo=data['id_tipo'])
        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])

            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Algo salio mal ):'}, 500
コード例 #11
0
ファイル: resources.py プロジェクト: muyani/authService
    def post(self):
        if request.is_json:
            try:
                fullName = request.get_json()['fullName']
                email = request.get_json()['email']
                password = request.get_json()['password']
            except Exception as e:
                capture_exception(e)
                return {"Message": "Some field is empty"}, 400
        else:
            capture_message("None JSON data sent")
            return {"Message": "Request body is null/not JSON"}, 400

        if UserModel.find_by_email(email):
            return {
                "Message": "Email {} already registered".format(email)
            }, 409
        try:
            user = UserModel(fullName=fullName,
                             email=email,
                             password=UserModel.generate_hash(password))
            user.save_to_db()
            access_token = create_access_token(identity=email)
            refresh_token = create_refresh_token(identity=email)
            return {
                'message': 'User {} was created'.format(email),
                'access_token': access_token,
                'refresh_token': refresh_token
            }, 200
        except Exception as e:
            capture_exception(e)
            return {"Message": "Unable to create user"}, 500
コード例 #12
0
ファイル: views.py プロジェクト: bogerv/moe
    def post(self):
        data = parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']))

        try:
            new_user.save_to_db()

            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])

            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #13
0
ファイル: users.py プロジェクト: riftadi/trashure
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument("username",
                            help="This field cannot be blank",
                            required=True)
        parser.add_argument("password",
                            help="This field cannot be blank",
                            required=True)

        data = parser.parse_args()

        if UserModel.find_by_username(data["username"]):
            return {
                "message": "User {} already exists".format(data["username"])
            }

        new_user = UserModel(username=data["username"],
                             password=UserModel.generate_hash(
                                 data["password"]),
                             score=0)

        try:
            new_user.add_to_db()
            access_token = create_access_token(identity=data["username"])
            refresh_token = create_refresh_token(identity=data["username"])
            return {
                "message": "User {} was created".format(data["username"]),
                "access_token": access_token,
                "refresh_token": refresh_token
            }
        except:
            return {"message": "Something went wrong"}, 500
コード例 #14
0
 def put(self, id):
     parser.add_argument('password',
                         help='This field cannot be blank',
                         required=True)
     data = parser.parse_args()
     return UserModel.update_user(id, data['username'],
                                  UserModel.generate_hash(data['password']))
コード例 #15
0
    def post(self):
        data = registration_parser.parse_args()

        if UserModel.find_by_username(
                data['username']) or UserModel.find_by_email(data['email']):
            return {
                'message': "User with such username or email already exists"
            }, 400

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             email=data['email'],
                             name=data['name'],
                             surname=data['surname'],
                             current_balance=100)

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=new_user)
            refresh_token = create_refresh_token(identity=new_user)
            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #16
0
ファイル: resources.py プロジェクト: nurchulis/API_ResponeAPP
    def post(self):
        data = register.parse_args()

        if UserModel.find_by_username(data['username']):
            return {
                'success': 'false',
                'message': 'User {} already exists'.format(data['username'])
            }

        if UserModel.find_by_email(data['email']):
            return {
                'success': 'false',
                'message': 'Email {} already exists'.format(data['email'])
            }

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             email=data['email'],
                             kantor=data['kantor'],
                             no_hp=data['no_hp'],
                             alamat=data['alamat'])

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'success': 'true',
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'success': 'false'}, 500
コード例 #17
0
ファイル: resources.py プロジェクト: jschmidtnj/healthtech19
    def post(self):
        data = registration_parser.parse_args()

        if UserModel.find_by_email(data['email']):
            return {
                'message': 'User {} already exists'.format(data['email'])
            }, 400

        new_user = UserModel(email=data['email'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             first_name=data['first_name'],
                             last_name=data['last_name'],
                             phone=data['phone'],
                             gender=data['gender'],
                             dob=data['dob'],
                             dod=data['dod'],
                             medications=[],
                             heatmap=[])

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['email'])
            refresh_token = create_refresh_token(identity=data['email'])
            return {
                'message': 'User {} was created'.format(data['email']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except Exception as e:
            print(e)
            return {'message': 'Something went wrong'}, 500
コード例 #18
0
    def post(self, args):
        current_user = UserModel.find_by_username(args.get('username'))
        if not current_user:
            return {
                'message':
                'User {} doesn\'t exist'.format(args.get('username'))
            }

        if UserModel.verify_hash(args.get('password'), current_user.password):
            current_user.password = UserModel.generate_hash(
                args.get('new_password'))
            try:
                current_user.save_to_db()
                access_token = create_access_token(
                    identity=args.get('username'))
                refresh_token = create_refresh_token(
                    identity=args.get('username'))
                return {
                    'message':
                    'User {}: Your password has been reset'.format(
                        args.get('username')),
                    'access_token':
                    access_token,
                    'refresh_token':
                    refresh_token
                }
            except (Exception, ):
                return {'message': 'Something went wrong'}, 500
        else:
            return {'message': 'username or password is incorrect'}, 400
コード例 #19
0
    def post(self):
        data = parser.parse_args()

        if UserModel.find_by_email(data['email']):
            return {
                'message': 'User {} already exists'.format(data['email'])
            }, 400
        random_char = ''.join([
            random.choice(string.ascii_letters + string.digits)
            for n in range(8)
        ])
        content = "your password for kaala app is " + random_char
        mail = ""
        password = ""
        self.send_email(mail, password, data['email'], content)
        new_user = UserModel(emp_id=data['emp_id'],
                             email=data['email'],
                             password=UserModel.generate_hash(random_char),
                             role=data['role'])

        try:
            new_user.save_to_db()
            return {
                'message': 'User {} is created'.format(data['email']),
                'password': random_char
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #20
0
ファイル: user.py プロジェクト: frannale/trenServer
        def post(self, **kwargs):
            data = kwargs

            # SOLO ADMIN
            if not UserModel.is_admin(get_jwt_identity()):
                return {'exito': False, 'message': 'Acceso denegado'}

            current_user = UserModel.find_by_username(data['username'], False)
            if current_user:
                current_user.close_connection()
                return {
                    'exito': False,
                    'message': 'Ya existe un usuario con ese nombre'
                }

            if data['role'] not in ['admin', 'lector']:
                return {
                    'exito': False,
                    'message': 'El rol debe ser admin o lector'
                }

            #CREA USER
            new_user = UserModel(role=data['role'],
                                 username=data['username'],
                                 password=UserModel.generate_hash(
                                     data['password']))
            new_user.save_to_db()

            return {
                'exito':
                True,
                'message':
                'Usuario {} creado exitosamente!'.format(data['username']),
            }
コード例 #21
0
    def post(self):
        data = parserRegister.parse_args()
        if UserModel.find_by_email(data['email']):
            return {
                'message':
                'User with email {} already exists'.format(data['email'])
            }, 409

        if not fullmatch(r"[^@]+@[^@]+\.[^@]+", data['email']):
            return {
                'message':
                'Email address {} is not valid'.format(data['email'])
            }, 400

        new_user = UserModel(email=data['email'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             model_id=uuid.uuid4().hex)

        try:
            new_user.save_to_db()
            new_user.create_model(json.loads(data['train']))
            return {
                'message': 'User {} was created'.format(data['email']),
            }
        except Exception as e:
            print(e)
            return {'message': 'Something went wrong'}, 500
コード例 #22
0
ファイル: resources.py プロジェクト: zeroam/TIL
    def post(self):
        data = parser.parse_args()

        username = data["username"]

        # Checking that user is already exist or not
        if UserModel.find_by_username(username):
            return {"message": f"User {username} already exists"}

        # create new user
        new_user = UserModel(
            username=username,
            password=UserModel.generate_hash(data["password"])
        )

        try:
            # Saving user in DB and Generating Access and Refresh token
            new_user.save_to_db()
            access_token = create_refresh_token(identity=username)
            refresh_token = create_refresh_token(identity=username)

            return {
                "message": f"User {username} was created",
                "access_token": access_token,
                "refresh_token": refresh_token,
            }
        except:
            return {"message": "Something went wrong"}, 500
コード例 #23
0
    def post(self):
        data = registerParser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {'message': 'User {} already exists'. format(data['username'])}

        new_user = UserModel(
            username = data['username'],
            password = UserModel.generate_hash(data['password']),
            firstname = data['firstName'],
            lastname = data['lastName']
        )


        try:
            new_user.save_to_db()
            access_token = create_access_token(identity = data['username'])
            refresh_token = create_refresh_token(identity = data['username'])
            url='http://129.213.87.202:3000/api/org.example.biznet.Trader'
            payload={"$class": "org.example.biznet.Trader", "traderId": data['username'], "firstName": data['firstName'], "lastName": data['lastName'] }
            headers={'Content-Type': 'application/json'}
            response = requests.post(url, data=json.dumps(payload), headers=headers)

            return {
                'message': 'User {} was created'.format( data['username'])
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #24
0
 def post(self):
     data = register_validate().parse_args()
     if not validate_email(email=data['email'],
                           verify=True,
                           check_mx=True,
                           smtp_timeout=10,
                           dns_timeout=10,
                           use_blacklist=True,
                           debug=False):
         return {'message': 'Invalid Email'}, 422
     if not re.match('^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$',
                     data['password']):
         return {'message': 'Stronger Password required'}, 422
     if UserModel.check_by_username(data['email']):
         return {
             'message': 'User {} already exists'.format(data['email'])
         }, 422
     else:
         new_user = UserModel()
         new_user.username = data['email'],
         new_user.firstname = data['first_name']
         new_user.password = UserModel.generate_hash(data['password'])
         try:
             new_user.save_to_db()
             access_token = create_access_token(identity=data['email'][0])
             refresh_token = create_refresh_token(identity=data['email'][0])
             return {
                 'message': 'User {} was created'.format(data['email']),
                 'access_token': access_token,
                 'refresh_token': refresh_token
             }
         except:
             return {'message': 'Something went wrong'}, 500
コード例 #25
0
ファイル: resources.py プロジェクト: frederiksberg/modsec_api
    def post(self):
        req_user = UserModel.find_by_username(get_jwt_identity())
        failed, msg = verify_admin(req_user)
        if failed: return msg

        data = parser.parse_args()

        if UserModel.find_by_username(data["username"]):
            return {"message": f"User {data['username']} already exists"}

        new_user = UserModel(username=data["username"],
                             access_level="USER",
                             password=UserModel.generate_hash(
                                 data["password"]))

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data["username"])
            refresh_token = create_refresh_token(identity=data["username"])
            return {
                "message": f"User {data['username']} was created!",
                "access_token": access_token,
                "refresh_token": refresh_token
            }
        except:
            return {"message": "An error occured while creating user"}
コード例 #26
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('email',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('password',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('name',
                            help='This field cannot be blank',
                            required=True)
        data = parser.parse_args()

        if UserModel.find_by_email(data['email']):
            return {
                'message': 'User {} already exists'.format(data['email'])
            }, 409

        new_user = UserModel(name=data['name'],
                             email=data['email'],
                             password=UserModel.generate_hash(
                                 data['password']))

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['email'])
            return {
                'message': 'User {} was created'.format(data['email']),
                'access_token': access_token
            }
        except:
            return {'message': 'Something went wrong'}, 500
コード例 #27
0
    def post(self):
        name = parser4.parse_args()['email']
        q = parser4.parse_args()['security-question']
        sec_a = parser4.parse_args()['security-answer']
        password = parser4.parse_args()['new-password']

        ques = [
            "What is your hometown's name?",
            "What is/was your first pet's name?",
            "Who is your favorite author?",
            "Who is your favorite character in your favorite show?"
        ]

        sec_q = -1
        for i, el in enumerate(ques):
            if el == q:
                sec_q = i
                break

        try:
            if UserModel.check_security_qa(name, sec_q, sec_a):
                UserModel.update_password(name,
                                          UserModel.generate_hash(password))
            else:
                return {"res": "Failed Check"}, 404
        except:
            return {"res": "Something went wrong"}, 500
コード例 #28
0
ファイル: __init__.py プロジェクト: ntohidi/flask-jwt
    def post(self):
        data = parser.parse_args()
        user = UserModel.check_for_conflict(
            args={'username': data['username']})
        if user.json['user']:
            return {
                'status': 409,
                'message': 'username {} exists'.format(data['username'])
            }, 409

        new_user = UserModel({
            "username":
            data['username'],
            "password":
            UserModel.generate_hash(data['password'])
        })
        try:
            new_user.save()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'status': 200,
                'message': 'User created',
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except Exception as err:
            print(err.args)
            return {
                'status': 500,
                'message': 'Something went horribly wrong'
            }, 500
コード例 #29
0
ファイル: run.py プロジェクト: sumeet-/flask_jwt
def populate_example_data():
    example_users = [('hermione', 'granger'), ('ron', 'weasley'),
                     ('nevil', 'longbottom')]
    for username, password in example_users:
        new_user = UserModel(username=username,
                             password=UserModel.generate_hash(password))
        try:
            new_user.save_to_db()
        except:
            return
コード例 #30
0
ファイル: resources.py プロジェクト: sedashov/unicredit
    def post(self, token):
        user = UserModel.verify_reset_password_token(token)
        if not user:
            return {'message': 'Verification failed. Please try again'}, 400
        data = after_confirmation_password_change_parser.parse_args()
        user.change_password(UserModel.generate_hash(data['new_password']))
        access_token = create_access_token(identity=user)
        refresh_token = create_refresh_token(identity=user)

        return {'message': 'You have successfully changed your password!', 'access_token': access_token, 'refresh_token': refresh_token}