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
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
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
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
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
def t2(): user = { "last_name": "Gamgee", "first_name": "Sam", "email": "*****@*****.**", "password": "******" } r = UserService.create_user(user) print("Result = ", r)
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
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
def delete(cls, url, target_usr, token): auth = security.authorize(url=url, method="DELETE", token=token, target_usr=target_usr) logger.debug("auth: " + str(auth)) if auth: try: result = user_svc.delete_user(target_usr) return result except: return None else: return None
def t1(): r = UserService.get_by_email('*****@*****.**') print("Result = \n", json.dumps(r, indent=2))
def register(): last_name = request.args.get("last_name") first_name = request.args.get("first_name") email = request.args.get("email") password = request.args.get("password") valid = all([last_name, first_name, email, password]) user_info = { "last_name": last_name, "first_name": first_name, "email": email, "password": password, "id": str(uuid4()), "status": "PENDING" } inputs = log_and_extract_input( register, { "last_name": last_name, "first_name": first_name, "email": email, "password": password }) # http://127.0.0.1:5000/api/registrations?last_name=asd&first_name=dsa&email=fdsafdsgf&password=1123 # If invalid argument if not valid: rsp = Response( "Some columns are empty. last_name, first_name, email, password are required", status=200, content_type="test/plain") return rsp user_data = UsersRDB.get_by_email(user_info["email"], include_deleted=True) if user_data: if user_data.get("status", None) != "PENDING": rsp = Response("User already exist", status=400, content_type="test/plain") return rsp else: notification.publish_it(email) rsp = Response("User " + user_data.get("id", "") + " already exist, resent activation email.", status=200, content_type="test/plain") return rsp try: # result = UsersRDB.create_user(user_info) result = UserService.create_user(user_info) rsp = Response("User created, user ID is:" + (result if result else "") + " please verify your email", status=200, content_type="test/plain") except Exception as e: rsp = Response("Invalid argument", status=400, content_type="test/plain") logger.debug(str(e)) return rsp