def set_password(self, new_password): """ Sets the password for an admin. """ if not self.id: raise ValidationError('An admin is not associated with the object') min_pwd_length = int(Configs.query.filter_by(setting='Minimum Password Length').first().value) if len(new_password) < min_pwd_length: raise ValidationError('The password must be at least {0} characters long'.format(min_pwd_length)) self.password = bcrypt.generate_password_hash(new_password)
def set_password(self, new_password): """ Sets the password for an admin. """ if not self.id: raise ValidationError('An admin is not associated with the object') min_pwd_length = int(Configs.query.filter_by( setting='Minimum Password Length').first().value) if len(new_password) < min_pwd_length: error_msg = ('The password must be at least {0} characters long' .format(min_pwd_length)) raise ValidationError(error_msg) self.password = bcrypt.generate_password_hash(new_password)
def from_json(self, json): if not json.get('username', None): raise ValidationError('The username was not specified') if not json.get('password', None): raise ValidationError('The password was not specified') if not json.get('name', None): raise ValidationError('The name was not specified') if self.query.filter_by(username=json['username']).first() is not None: raise ValidationError('"{0}" already exists'.format( json['username'].lower())) min_pwd_length = int(Configs.query.filter_by(setting='Minimum Password Length').first().value) if len(json['password']) < min_pwd_length: raise ValidationError('The password must be at least {0} characters long'.format(min_pwd_length)) self.password = bcrypt.generate_password_hash(json['password']) self.username = json['username'].lower() self.name = json['name'] self.source = 'local' self.active = True return self
def from_json(self, json): if not json.get('username', None): raise ValidationError('The username was not specified') if not json.get('password', None): raise ValidationError('The password was not specified') if not json.get('name', None): raise ValidationError('The name was not specified') if self.query.filter_by(username=json['username']).first() is not None: raise ValidationError('"{0}" already exists'.format( json['username'].lower())) min_pwd_length = int(Configs.query.filter_by( setting='Minimum Password Length').first().value) if len(json['password']) < min_pwd_length: error_msg = ('The password must be at least {0} characters long' .format(min_pwd_length)) raise ValidationError(error_msg) self.password = bcrypt.generate_password_hash(json['password']) self.username = json['username'].lower() self.name = json['name'] self.source = 'local' self.active = True return self