def __init__(self, **kwargs): for property, value in kwargs.items(): if hasattr(value, '__iter__') and not isinstance(value, str): value = value[0] if property == 'password': value = hash_pass(value) setattr(self, property, value)
def __init__(self, **kwargs): for property, value in kwargs.items(): # depending on whether value is an iterable or not, we must # unpack it's value (when **kwargs is request.form, some values # will be a 1-element list) if hasattr(value, '__iter__') and not isinstance(value, str): # the ,= unpack of a singleton fails PEP8 (travis flake8 test) value = value[0] if property == 'password': value = hash_pass(value) # we need bytes here (not plain str) setattr(self, property, value)
def __init__(self, **kwargs): """ The constructor for User class. Attributes: self (User): The User object to manipulate kwargs (dict): The dictionary of arguments """ for property, value in kwargs.items(): # depending on whether value is an iterable or not, we must # unpack it's value (when **kwargs is request.form, some values # will be a 1-element list) if hasattr(value, '__iter__') and not isinstance(value, str): # the ,= unpack of a singleton fails PEP8 (travis flake8 test) value = value[0] if property == 'password': # Encrypt the password so it's not in plain text value = hash_pass(value) setattr(self, property, value)
def reset_password(): form = LoginForm(request.form) if 'reset' in request.form: email = request.form['email'] password = request.form['password'] password_old = request.form['password_old'] user = User.query.filter_by(email=email).first() if user and verify_pass(password_old, user.password): user.password = hash_pass(password) db.session.commit() return render_template('accounts/reset_password.html', msg='Contraseña cambiada', form=form) return render_template('accounts/reset_password.html', msg='Email o contraseña incorrectos', form=form) else: return render_template('accounts/reset_password.html', form=form)
def clean(self): self.password = hash_pass(self.password)