Exemple #1
0
    def do_register(self):
        if self.__has_logged():
            # We directly let that user log in
            return True, "Logged"

        try:
            db = tingDB_service.get_config_db()
            users = db["users"]

            # We first lookup if the user has been registered
            user_cursor = users.find({"name": self.__username})
            if user_cursor.count() > 0:
                return False, "This user name has been registered."

            # Prepare for user record
            raw_password = self.__password
            encrypted_password = utils.encrypt_string(raw_password)

            new_user = {"name": self.__username, "password": encrypted_password, "privilege": "normal"}

            users.insert(new_user)
            register_user_cache(self)

            return True, "Register successfully."
        except Exception, e:
            print e.message
Exemple #2
0
    def do_login(self):
        if self.__has_logged():
            return True, "Logged"

        try:
            db = tingDB_service.get_config_db()
            users = db["users"]
            users = users.find({"name": self.__username})

            # results is in the type of Cursor
            if users.count() == 1:
                user = users.next()
                raw_password = self.__password
                encrypted_password = utils.encrypt_string(raw_password)

                if user["password"] == encrypted_password:
                    register_user_cache(self)
                    return True, "Corrected"

                self.__privilege = user["privilege"]
        except Exception, e:
            # Connect to database failed
            print e.message
Exemple #3
0
 def write_object_as_json(self, key, obj):
   serialized = json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': '))
   encrypted = utils.encrypt_string(serialized, key)
   k = boto.s3.key.Key(self.bucket)
   k.key = key
   k.set_contents_from_string(encrypted)
Exemple #4
0
def insert_user(pseudo, passe):
    new_user = User(pseudo, encrypt_string(passe), 0, '#000000')
    db.session.add(new_user)
    db.session.commit()