Beispiel #1
0
    def update_password(self, u, newpass):
        '''
        Updates the user's password. Assumes that the password has been
        validated.

        @param u: The user to update. Can be an integer for the uid, a username,
                  or a user object.
        @param newpass: The new password.
        '''
        user = self.get_user(u)

        if user is not None:
            user.passhash = mainCrypt.generate_password_hash(newpass)
            mainDB.session.commit()
        else:
            raise UserNotFound("User not found in database")
Beispiel #2
0
    def add(self, username, password, fullname, bio="", group=None,
            active=False):
        '''
        Adds a user to the database.

        @param username: The username to add, must be unique.
        @param password: The password to use.
        @param fullname: The user's full name
        @param bio: The user's bio (optional)
        @param group: The user's primary group (optional)
        @param active: Whether the user is active or not

        @return The user object for the user crated.
        '''
        try:
            exists = self.find_user_by_name(username)
        except:
            exists = False

        if exists:
            raise DuplicateUser("{0} already exists in database with id '{1}'".
                format(username, str(exists)))
        else:
            from noink.role_db import RoleDB
            role_db = RoleDB()
            passHash = mainCrypt.generate_password_hash(password)
            u = User(username, fullname, bio, passHash)
            if group is None:
                group = self.get_group(mainApp.config['DEFAULT_GROUP'])
            u.primary_group = group
            u.active = active
            mainDB.session.add(u)
            mainDB.session.commit()
            self.eventLog.add('add_user', u.id, True, None, username)
            self.add_to_group(u, group)
            role_db.assign_role(u, group, mainApp.config['DEFAULT_ROLE_NAME'])
            return u