示例#1
0
def updatepassword():
    post_data = request.get_json()
    response_object = {'status': 'fail', 'message': 'Invalid Information'}
    if not post_data:
        return jsonify(response_object), 400
    token = post_data.get('token')
    email = decode_token(token, 'password-reset-salt')
    new_password = post_data.get('password')

    try:
        user = User.query.filter_by(email=email).first()
        #Mongo
        user_m = User_M.objects(__raw__={'email': email}).first()
        if not user or not user_m:
            response_object['status'] = 'Fail'
            response_object['message'] = 'User not found'
            return jsonify(response_object), 400
        else:
            hashed_password = bcrypt.generate_password_hash(
                new_password,
                current_app.config.get('BCRYPT_LOG_ROUNDS')).decode()
            user.password = hashed_password
            user_m.password = hashed_password
            db.session.commit()
            user_m.save()

            response_object['status'] = 'Success'
            response_object[
                'message'] = 'Updated password. Login using your new password'
            return jsonify(response_object), 201
    except (exc.IntegrityError, ValueError) as e:
        return jsonify(response_object), 400
示例#2
0
 def put(self, id):
     try:
         data = request.get_json()
         data['password'] = bcrypt.generate_password_hash(data['password'])
         User.query.filter_by(id=id).update(data)
         db.session.commit()
         return self.make_response('User updated successfully.')
     except IntegrityError as error:
         return self.make_response(error.message, 400)
示例#3
0
 def set_password(self, password):
     self.password = bcrypt.generate_password_hash(password)
示例#4
0
	def __init__(self, firstname, lastname, email, password):
		self.firstname = firstname
		self.lastname = lastname
		self.email = email	
		self.password = bcrypt.generate_password_hash(password, current_app.config.get('BCRYPT_LOG_ROUNDS')).decode()