예제 #1
0
 def create_new_user(name, surname, password, email):
     user = User(settings.DB_NAME)
     users_data = (name, surname, utils.encode_password(password),
                   datetime.datetime.now(), email)
     c = user.db_worker.conn.cursor()
     c.execute(
         "INSERT into users (user_name, user_surname, password, reg_date, email) VALUES (?,?,?,?,?)",
         users_data)
     user.db_worker.conn.commit()
     new_user = User.get_user_by_login(name)
     return new_user
예제 #2
0
def login(request):
    if request['method'] == 'POST':
        current_user = User.get_user_by_login(request['POST']['login'])
        if encode_password(
                request['POST']['password']) == current_user.password:
            user_session = UsersSession(settings.DB_NAME, current_user)
            request['session'] = user_session.token
            return Redirect('', request)
        print('Method POST')
    elif request['method'] == 'GET':
        print('Method GET')
    return render_template('templates/authorization.html')
예제 #3
0
    def forgot_password(email):
        "send an email to the user"
        if not email:
            return False

        query = datamodel.User.all()
        query.filter('email =', email)
        user = query.get()

        if user:
            raw_password = SecurityService.random_string(user)[:8]
            user.password = utils.encode_password(raw_password)
            user.put()

            emailservice.send_password_reset(user, raw_password)

            user.set_dirty(True)
            user.update_cache_if_dirty()
            return True

        return False
 def forgot_password(email):
     "send an email to the user"
     if not email:
         return False
     
     query = datamodel.User.all()
     query.filter('email =', email)
     user = query.get()   
     
     if user:
         raw_password = SecurityService.random_string(user)[:8]
         user.password = utils.encode_password(raw_password)
         user.put()
     
         emailservice.send_password_reset(user, raw_password)
         
         user.set_dirty(True)
         user.update_cache_if_dirty()            
         return True
     
     return False
예제 #5
0
 def data_seeding_users(self):
     """
     to fill a table "users" with a test data
     """
     user_name = 'John'
     user_surname = 'Connor'
     reg_date = '1985-01-01'
     hex_pass = encode_password('Secret')
     users_data = (user_name, user_surname, hex_pass, reg_date)
     try:
         c = self.conn.cursor()
         c.execute(data_seeding_user_command_1)
         c.execute(data_seeding_user_command_2)
         c.execute(data_seeding_user_command_3)
         c.execute(
             "INSERT into users (user_name, user_surname, password, reg_date) VALUES (?,?,?,?)",
             (users_data))
         self.conn.commit()
         logger.debug(f'Data seeding for the "Users" table were done')
     except Exception as e:
         logger.critical(
             'Failed data seeding for users table, error print from create_tasks_table',
             e)
예제 #6
0
    def register_user(user, app=None):
        "register a new user"
        u = datamodel.User.get_or_insert(user['email'])

        if not u.email:
            for k in user:
                setattr(u, k, user[k])
            u.password = utils.encode_password(u.password)
            u.activation_code = None  #SecurityService.random_string(u)
            u.chat_id = ''
            u.is_active = True
            u.put()

            SecurityService.add_user_app_perms(u, app)

            u.set_dirty(True)
            u.update_cache_if_dirty()

            logging.info("Sending activation email: %s " % u.email)
            emailservice.send_activation_email(u)
            return u

        return None
 def register_user(user, app=None):
     "register a new user"
     u = datamodel.User.get_or_insert(user['email'])
     
     if not u.email:
         for k in user:
             setattr(u, k, user[k])     
         u.password = utils.encode_password(u.password)       
         u.activation_code = None #SecurityService.random_string(u)
         u.chat_id = ''
         u.is_active = True
         u.put()
         
         SecurityService.add_user_app_perms(u, app)
         
         u.set_dirty(True)
         u.update_cache_if_dirty()
         
         logging.info("Sending activation email: %s " % u.email)
         emailservice.send_activation_email(u)
         return u
     
     return None
def import_password(x):
    ret = utils.encode_password(x)
    return ret
예제 #9
0
        else:
            user_token = list_tokens[
                -1]  # уточнить как более изящно получить str значение
            # try except
            c.execute("SELECT user FROM users_session where token=(?)",
                      (str(user_token), ))
            userid = c.fetchone()
        return int(
            userid[0])  # уточнить как более изящно получить извлечь значение

    # def generate_new_token(self):
    #     token = utils.gen_session_token()
    #     db_worker = DataWork(settings.DB_NAME)
    #
    #     c = db_worker.conn.cursor()
    #     c.execute("SELECT token FROM users_session")


if __name__ == '__main__':
    current_user_login = '******'
    current_password = '******'
    current_user = User.get_user_by_login(current_user_login)
    if utils.encode_password(current_password) == current_user.password:
        user_session = UsersSession(settings.DB_NAME, current_user)
        token = user_session.token
        print(token)
        print(user_session.expires_date)
    # User.get_user_by_login('John')
    # User.create_new_user('Mike2', 'Surface2', 'Secret3')
    pass
def import_password(x):
    ret = utils.encode_password(x)
    return ret