Beispiel #1
0
    def create(self, username, password, completename=None):
        """
            Init the user model, and save it in DB
        """
        if User.query.filter_by(nickname=username).count() != 0:
            return False
        password = encrypt_password(password)
        user_datastore.create_user(nickname=username,
                                   password=password,
                                   completename=completename,
                                   active=False)

        myuser = User.query.filter_by(nickname=username).first()
        # TODO : manage API key with flask-login
        apikey_seed = str(random.randint(0, 0xFFFFFFFFFFFFFFFF))
        apikey_seed = apikey_seed + str(int(time.time()))
        apikey_seed = apikey_seed + sha256(username).hexdigest()
        apikey_seed = apikey_seed + sha256(password).hexdigest()
        apikey_seed = ''.join(random.sample(apikey_seed, len(apikey_seed)))
        myuser.api_key = sha256(apikey_seed).hexdigest()

        myuser.theme = "default"

        # the first user is active and admin
        if User.query.count() == 1:
            role = user_datastore.find_or_create_role("admin",
                                                      description="Administrator")
            if role is not None:
                user_datastore.add_role_to_user(myuser, role)
            else:
                app.logger.error("Cannot find and affect admin role to user")
            user_datastore.activate_user(myuser)

        db.session.commit()
        return True
Beispiel #2
0
 def activate(user_id):
     u = User.query.get(int(user_id))
     if u is not None:
         user_datastore.activate_user(u)
         db.session.commit()
         return True
     return False
Beispiel #3
0
    def create(self, username, password, completename=None):
        """
            Init the user model, and save it in DB
        """
        if User.query.filter_by(nickname=username).count() != 0:
            return False
        password = encrypt_password(password)
        user_datastore.create_user(nickname=username,
                                   password=password,
                                   completename=completename,
                                   active=False)

        myuser = User.query.filter_by(nickname=username).first()
        # TODO : manage API key with flask-login
        apikey_seed = str(random.randint(0, 0xFFFFFFFFFFFFFFFF))
        apikey_seed = apikey_seed + str(int(time.time()))
        apikey_seed = apikey_seed + sha256(username).hexdigest()
        apikey_seed = apikey_seed + sha256(password).hexdigest()
        apikey_seed = ''.join(random.sample(apikey_seed, len(apikey_seed)))
        myuser.api_key = sha256(apikey_seed).hexdigest()

        myuser.theme = "default"

        # the first user is active and admin
        if User.query.count() == 1:
            role = user_datastore.find_or_create_role(
                "admin", description="Administrator")
            if role is not None:
                user_datastore.add_role_to_user(myuser, role)
            else:
                app.logger.error("Cannot find and affect admin role to user")
            user_datastore.activate_user(myuser)

        db.session.commit()
        return True
Beispiel #4
0
 def activate(user_id):
     u = User.query.get(int(user_id))
     if u is not None:
         user_datastore.activate_user(u)
         db.session.commit()
         return True
     return False
Beispiel #5
0
    def create(self, username, password, completename=None):
        """
            Init the user model, and save it in DB
        """
        if User.query.filter_by(nickname=username).count() != 0:
            return False
        password = encrypt_password(password)
        user_datastore.create_user(nickname=username,
                                   password=password,
                                   completename=completename,
                                   active=False)

        myuser = User.query.filter_by(nickname=username).first()
        # TODO : manage API key with flask-login
        apikey_seed = str(random.randint(0, 0xFFFFFFFFFFFFFFFF))
        apikey_seed = apikey_seed + str(int(time.time()))
        apikey_seed = apikey_seed + sha256(username).hexdigest()
        apikey_seed = apikey_seed + sha256(password).hexdigest()
        apikey_seed = ''.join(random.sample(apikey_seed, len(apikey_seed)))
        myuser.api_key = sha256(apikey_seed).hexdigest()

        myuser.theme = "default"

        # the first user is active and admin
        if User.query.count() == 1:
            self.manage_admin_role(myuser.id)
            user_datastore.activate_user(myuser)
        db.session.commit()
        return True
Beispiel #6
0
    def create(self, username, password, completename=None):
        """
            Init the user model, and save it in DB
        """
        if User.query.filter_by(nickname=username).count() != 0:
            return False
        password = encrypt_password(password)
        user_datastore.create_user(nickname=username,
                                   password=password,
                                   completename=completename,
                                   active=False)

        myuser = User.query.filter_by(nickname=username).first()
        myuser.theme = "default"

        myuser.api_key = self.generate_api_key(username, password)

        # the first user is active and admin
        if User.query.count() == 1:
            self.manage_admin_role(myuser.id)
            user_datastore.activate_user(myuser)
        db.session.commit()
        return True