def add_user(<EOL>self,<EOL>username,<EOL>first_name,<EOL>last_name,<EOL>email,<EOL>role,<EOL>password="<STR_LIT>",<EOL>hashed_password="<STR_LIT>",<EOL>):
try:<EOL><INDENT>user = self.user_model()<EOL>user.first_name = first_name<EOL>user.last_name = last_name<EOL>user.username = username<EOL>user.email = email<EOL>user.active = True<EOL>user.roles.append(role)<EOL>if hashed_password:<EOL><INDENT>user.password = hashed_password<EOL><DEDENT>else:<EOL><INDENT>user.password = generate_password_hash(password)<EOL><DEDENT>user.save()<EOL>log.info(c.LOGMSG_INF_SEC_ADD_USER.format(username))<EOL>return user<EOL><DEDENT>except Exception as e:<EOL><INDENT>log.error(c.LOGMSG_ERR_SEC_ADD_USER.format(str(e)))<EOL>return False<EOL><DEDENT>
Generic function to create user