Example #1
0
    def update(cls, url, target_usr, token, update_data, Etag):
        auth = security.authorize(url=url,
                                  method="PUT",
                                  token=token,
                                  target_usr=target_usr)
        logger.debug("auth: " + str(auth))
        if auth:
            cur_usr_info = user_svc.get_by_email(target_usr)
            cur_usr_info = json.dumps(cur_usr_info, sort_keys=True)
            logger.debug("cur_usr_info: " + str(cur_usr_info))

            etag = security.ETag(Etag=Etag, cur_usr_info=cur_usr_info)
            if etag:
                hashed_pw = security.hash_password(
                    {"password": update_data['password']})
                update_data["password"] = hashed_pw

                logger.debug("************" + str(update_data["password"]))

                try:
                    result = user_svc.update_user(update_data, target_usr)
                    s_info = user_svc.get_by_email(update_data['email'])
                    tok = security.generate_token(s_info)
                    return "success", tok, s_info
                except:
                    return "exception", None, None
            else:
                return "Content Conflict", None, None
        else:
            return "No authentication", None, None
Example #2
0
 def fb_login(cls, login_info):
     s_info = user_svc.get_by_email(login_info['email'])
     if s_info is not None:
         tok = security.generate_token(s_info)
         return tok
     else:
         return False
Example #3
0
    def register(cls, data):

        hashed_pw = security.hash_password({"password": data['password']})
        data["password"] = hashed_pw
        result = user_svc.create_user(data)
        s_info = user_svc.get_by_email(data['email'])
        tok = security.generate_token(s_info)
        return result, tok
Example #4
0
 def login(cls, login_info):
     test = security.hash_password({"password": login_info['password']})
     print(test)
     s_info = user_svc.get_by_email(login_info['email'])
     if test == s_info['password']:
         tok = security.generate_token(s_info)
         return tok
     else:
         return None
Example #5
0
    def login(cls, login_info):
        test = security.hash_password({"password": login_info['password']})
        s_info = user_svc.get_by_email(login_info['email'])
        if s_info is None:
            return None, None

        if str(test) == s_info['password']:
            etag = security.generate_etag(s_info)
            tok = security.generate_token(s_info)
            return tok, etag
        else:
            return None, None
Example #6
0
 def login(cls, login_info):
     # Why hash that? Is that password informal?
     test = security.hash_password({"password" : login_info['password']})
     # test = login_info['password']
     logger.debug("LOGIN_INFO" + str(test))
     s_info = user_svc.get_by_email(login_info['email'])
     logger.debug("SLOGIN_INFO" + str(s_info))
     test = str(test)
     if s_info and str(test) == s_info['password']:
         tok = security.generate_token(s_info)
         return tok, s_info
     else:
         return False
Example #7
0
 def register(cls, data):
     hashed_pw = security.hash_password({"password" : data['password']})
     data["password"] = hashed_pw
     try:
         result = user_svc.create_user(data)
         logger.debug("CREATE RESULT: " + str(result))
         s_info = user_svc.get_by_email(data['email'])
         logger.debug("CREATE S_INFO: " + str(s_info))
         tok = security.generate_token(s_info)
         logger.debug("CREATE TOK: " + str(tok))
         return tok, s_info
     except Exception as e:
         logger.error("CREATE ERROR: " + str(e))
         return None
Example #8
0
def t1():

    r = UserService.get_by_email('*****@*****.**')
    print("Result = \n", json.dumps(r, indent=2))