Exemple #1
0
    def post(self):
        parser = RequestParser()
        parser.add_argument('email', type=str)
        parser.add_argument('password', type=str)
        args = parser.parse_args()

        salted_string = (args['password'] + SALT)
        hashed_pwd = hash_sha(salted_string)
        if user_service.check_login(args['email'], hashed_pwd):
            return {'message': 'ok', 'token': user_service.get_token(args['email'], hashed_pwd)}
        else:
            return {'message': 'error'}
Exemple #2
0
 def post(self):
     try:
         parser = RequestParser()
         parser.add_argument('email', type=str)
         parser.add_argument('token', type=str)
         args = parser.parse_args()
         pwd = ''.join(choice(ascii_uppercase) for i in range(8))
         salted_string = (pwd + SALT)
         hashed_pwd = hash_sha(salted_string)
         UserService.create_user(args['email'], hashed_pwd, args['token'])
         send_mail(args['email'], "Account information",
                   "Hi, This is your temporary password for your account: " + pwd)
         return {'message': 'ok'}
     except:
         return {'message': 'error'}
Exemple #3
0
    def post(self):
        parser = RequestParser()
        parser.add_argument('email', type=str)
        parser.add_argument('password', type=str)
        args = parser.parse_args()

        salted_string = (args['password'] + SALT)
        hashed_pwd = hash_sha(salted_string)
        if user_service.check_login(args['email'], hashed_pwd):
            return {
                'message': 'ok',
                'token': user_service.get_token(args['email'], hashed_pwd)
            }
        else:
            return {'message': 'error'}
Exemple #4
0
 def post(self):
     try:
         parser = RequestParser()
         parser.add_argument('email', type=str)
         parser.add_argument('token', type=str)
         args = parser.parse_args()
         pwd = ''.join(choice(ascii_uppercase) for i in range(8))
         salted_string = (pwd + SALT)
         hashed_pwd = hash_sha(salted_string)
         UserService.create_user(args['email'], hashed_pwd, args['token'])
         send_mail(
             args['email'], "Account information",
             "Hi, This is your temporary password for your account: " + pwd)
         return {'message': 'ok'}
     except:
         return {'message': 'error'}
Exemple #5
0
    def create_token(cls, email, hashed_pwd):

        connection = get_connection()
        try:
            with connection.cursor() as cursor:

                sql = 'SELECT token FROM users FULL JOIN tokens WHERE tokens.email = %s AND password = %s'
                cursor.execute(sql, [email, hashed_pwd])
                seconds = cls.get_current_time_in_seconds()
                token = hash_sha(email + hashed_pwd + str(seconds) + SALT)
                if cursor.rowcount == 1:
                    sql = 'UPDATE tokens SET token = %s, date = %s WHERE email = %s'
                    cursor.execute(sql, [token, seconds, email])
                    connection.commit()
                    return token
                else:
                    sql = 'INSERT INTO tokens(email, token, date) VALUES (%s, %s, %s)'
                    cursor.execute(sql, [email, token, seconds])
                    connection.commit()
                    return token
        finally:
            connection.close()
        return None
Exemple #6
0
    def create_token(cls, email, hashed_pwd):

        connection = get_connection()
        try:
            with connection.cursor() as cursor:

                sql = 'SELECT token FROM users FULL JOIN tokens WHERE tokens.email = %s AND password = %s'
                cursor.execute(sql, [email, hashed_pwd])
                seconds = cls.get_current_time_in_seconds()
                token = hash_sha(email + hashed_pwd + str(seconds) + SALT)
                if cursor.rowcount == 1:
                    sql = 'UPDATE tokens SET token = %s, date = %s WHERE email = %s'
                    cursor.execute(sql, [token, seconds, email])
                    connection.commit()
                    return token
                else:
                    sql = 'INSERT INTO tokens(email, token, date) VALUES (%s, %s, %s)'
                    cursor.execute(sql, [email, token, seconds])
                    connection.commit()
                    return token
        finally:
            connection.close()
        return None