def login(self, user: User) -> None: engine: SessionStore = import_module(settings.SESSION_ENGINE) # Create a fake request to store login details. request = HttpRequest() if self.session: request.session = self.session else: request.session = engine.SessionStore() auth.login(user, request) # Save the session values. request.session.save() # Set the cookie to represent the session. session_cookie = settings.SESSION_COOKIE_NAME self.cookies[session_cookie] = request.session.session_key cookie_data = { "max-age": None, "path": "/", "domain": settings.SESSION_COOKIE_DOMAIN, "secure": settings.SESSION_COOKIE_SECURE or None, "expires": None, } self.cookies[session_cookie].update(cookie_data)
def run(): server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind((HOST, PORT)) server_socket.listen(5) actions = { 'ls': check, 'get': get, 'put': put, } while True: print('starting...') conn, addr = server_socket.accept() username = conn.recv(1024) password = conn.recv(1024) result = login(username, password) if result: conn.send('True'.encode('utf-8')) while True: cmd = conn.recv(1024) if not cmd: break cmd_list = cmd.decode('utf-8').split() if cmd_list[0] in actions: actions[cmd_list[0]](conn, cmd, result) else: conn.send('False'.encode('utf-8'))
def run(): ac_data=auth.login(User_data,access_logger) if(User_data['is_authenticated']): User_data['account_data']=ac_data interactive(User_data) #run()
def shop_list(): """主引导模块""" flag = True while flag: if not auth.login(): print(shopping_list) shop_count = input("\033[30;1m输入购买的商品号>>\033[0m").strip() if shop_count in shopping_price: merchandise_price = shopping_price[shop_count]["price"] merchandise_name = shopping_price[shop_count]["name"] with open( "%s\\user_account\\%s" % (user_path.path_list_db, auth.username), "r") as shop_r: user_account = json.loads(shop_r.read()) user_cash = user_account[auth.username]["cash"] user_deposit = user_account[auth.username]["deposit"] if int(merchandise_price) <= int(user_deposit): new_deposit = int(user_deposit) - int(merchandise_price) user_account[auth.username]["deposit"] = new_deposit with open( "%s\\user_account\\%s" % (user_path.path_list_db, auth.username), "w") as shop_w: shop_w.write(json.dumps(user_account)) print("用户:%s \n已购买:%s 花费:%s \n" "账户余额:%s" % (auth.username, merchandise_name, merchandise_price, new_deposit)) else: print("您的账户余额不足") shop_acc = input("\n任意键继续,退出请按q\n" ">>").strip() if shop_acc == "q": print("\033[32;1m\n(•‾⌣‾•) 谢谢回顾!!! \033[0m") flag = False
def run(): print("------- Oldboy Shopping Mall ---------") acc_data = auth.login(user_data, access_logger) if user_data['is_authenticated']: # user_data['account'] = acc_data['account'] user_data['shopping_cart'] = acc_data['shopping_cart'] user_data['shopping_record'] = acc_data['shopping_record'] interactive(user_data)
def wrapper(*args,**kwargs): if not Identity['user_status']: username=input('Username:'******'Password:'******'user_status']=True Identity['user_id']=username Identity['user_data']=user_data func(*args, **kwargs) else: func(*args,**kwargs)
def main(): ret = login() if ret['result']: # 如果用户登录成功,就展示用户选项,让用户输入序号去选择 print('\033[1;32;40m登录成功!\033[0m') # 带背景色输出 if hasattr(sys.modules[__name__], ret['id']): # 反射:检测是否存在这个类 cls = getattr(sys.modules[__name__], ret['id']) # 反射:得到这个类 # obj = cls(ret['name']) obj = cls.init(ret['name']) for id, (item, _) in enumerate(cls.operate_lst, 1): print(id, item) while 1: # 获取用户输入的数字,对应的函数名称 func_str = cls.operate_lst[int(input('请输入选项:')) - 1][1] if hasattr(obj, func_str): getattr(obj, func_str)()
def entry(): print("welcome to 3T system") user, ident = auth.login() print(sys.modules) file = sys.modules[__name__] print(file) cls = getattr(file, "core." + ident) obj = cls(user) newtodo = cls.TODO for num, i in enumerate(newtodo, 1): print(num, i[0]) choice = int(input("num>>")) choice_item = newtodo[choice - 1] getattr(obj, choice_item)()
def login_run(): print("欢迎登陆ATM") username = input("请输入用户名:").strip() password = input("请输入密码:").strip() a = auth.login(username) if a: if a.password == password: print("登陆成功,请输入您的操作:") """操作控制""" a.status(1) control.entrance(a) else: print("密码错误,请重新登录") else: print("用户名不存在")
def manage_auth(): # the functions will need data from the request if request.method == 'GET': auth = check_auth(session) if auth: return auth else: xml_res = ET.fromstring("<response></response>") msg = ET.Element('message') msg.text = 'NULL - You are not authenticated.' xml_res.append(msg) return ET.tostring(xml_res) elif request.method == 'POST': return login(request, session) elif request.method == 'DELETE': return logout(session)
def login(conn, data): """ 登录 :param conn: socket 连接对象 :param data: client 传输数据 :return: """ cmd, account, password = data.decode(CHARSET).split('|') uid = auth.login(account, password) if uid is None: uid = -1 conn.send(str(uid).encode(CHARSET)) return uid
def entry_point(): print('欢迎登录学生选课系统') print('请输入你的账号和密码') user,role = auth.login() file = sys.modules['__main__'] print(file) print(__file__) cls = getattr(__file__, role) # getattr(当前文件,'Manager') obj = cls(user) operate_dic = cls.OPERATE_DIC # print(operate_dic) while True: for num, i in enumerate(operate_dic, 1): print(num, i[0]) choice = int(input('num:')) choice_item = operate_dic[choice - 1] getattr(obj, choice_item[1])()
def controller(self, conn): '''''' while True: try: username = conn.recv(1024) password = conn.recv(1024) result = login(username, password) if result: conn.send('True'.encode('utf-8')) while True: cmd = conn.recv(1024) if not cmd: break cmd = cmd.decode('utf-8') func = getattr(self, '_%s' % cmd.split()[0]) func(conn, cmd, result) else: conn.send('Flase'.encode('utf-8')) except: break
def run(): """主函数""" print('\033[1;42m欢迎您登陆选课系统\033[0m') auth_msg = auth.login() # 接收登录之后的用户信息 if auth_msg: if auth_msg['roleid'] == 0: # 0表示管理员 obj = Manager(auth_msg['username']) # 实例化管理员对象 while True: for i, func in enumerate(Manager.menu, 1): # 取出类变量进行打印 print(i, func[1]) try: func_num = int(input("请输入功能序号:")) getattr(obj, Manager.menu[func_num - 1][0])() # 根据字符串从对象中找到对应的方法并执行(反射) except Exception as e: print("你输入的内容有误") elif auth_msg['roleid'] == 1: # 1表示讲师 obj = Teacher(auth_msg['username']) # 实例化管理员对象 while True: for i, func in enumerate(Teacher.menu, 1): # 取出类变量进行打印 print(i, func[1]) try: func_num = int(input("请输入功能序号:")) getattr(obj, Teacher.menu[func_num - 1][0])() # 根据字符串从对象中找到对应的方法并执行(反射) except Exception as e: print("你输入的内容有误") elif auth_msg['roleid'] == 2: # 2表示学生 obj = Student(auth_msg['username']) # 实例化管理员对象 for i, func in enumerate(Student.menu, 1): # 取出类变量进行打印 print(i, func[1]) try: func_num = int(input("请输入功能序号:")) getattr(obj, Student.menu[func_num - 1][0])() # 根据字符串从对象中找到对应的方法并执行(反射) except Exception as e: print("你输入的内容有误") else: print("你的角色出了问题,请联系管理员")
def process_login_request(request: HttpRequest) -> Union[Success, Error]: session_oauth_state = request.POST.get("serverState", None) request_oauth_state = request.POST.get("clientState", None) if (not session_oauth_state or not request_oauth_state or session_oauth_state != request_oauth_state): return Error( error="OAuthStateMismatch", error_description="State parameters must match.", ) # handle errors if request.POST.get("error"): return Error( error=request.POST.get("error"), error_description=request.POST.get("error_description"), ) code = request.POST.get("code") if not code: return Error( error="OAuthMissingCode", error_description="Payload should have a code parameter.", ) payload = dict( client_id=settings.KODIAK_API_GITHUB_CLIENT_ID, client_secret=settings.KODIAK_API_GITHUB_CLIENT_SECRET, code=code, ) access_res = requests.post("https://github.com/login/oauth/access_token", payload, timeout=5) try: access_res.raise_for_status() except (requests.HTTPError, requests.exceptions.Timeout): return Error(error="OAuthServerError", error_description="Failed to fetch access token.") access_res_data = dict(parse_qsl(access_res.text)) access_token_error = access_res_data.get("error") if access_token_error: return Error( error=access_token_error, error_description=access_res_data.get("error_description", ""), ) access_token = access_res_data.get("access_token") if not access_token: return Error( error="OAuthMissingAccessToken", error_description="OAuth missing access token.", ) # fetch information about the user using their oauth access token. user_data_res = requests.get( "https://api.github.com/user", headers=dict(authorization=f"Bearer {access_token}"), timeout=5, ) try: user_data_res.raise_for_status() except (requests.HTTPError, requests.exceptions.Timeout): return Error( error="OAuthServerError", error_description= "Failed to fetch account information from GitHub.", ) user_data = user_data_res.json() github_login = user_data["login"] github_account_id = int(user_data["id"]) existing_user: Optional[User] = User.objects.filter( github_id=github_account_id).first() if existing_user: existing_user.github_login = github_login existing_user.github_access_token = access_token existing_user.save() user = existing_user else: user = User.objects.create( github_id=github_account_id, github_login=github_login, github_access_token=access_token, ) # TODO(chdsbd): Run this in as a background job if the user is an existing # user. try: user.sync_accounts() except SyncAccountsError: logger.warning("sync_accounts failed", exc_info=True) # ignore the errors if we were an existing user as we can use old data. if not existing_user: return Error( error="AccountSyncFailure", error_description="Failed to sync GitHub accounts for user.", ) auth.login(user, request) return Success()
def run(): """执行模块""" auth.login() main_main(auth.username)
def login(request, format=None): """Redirect to CAS with a callback pointing to login_callback""" return auth_view.login(request, format)
def login(grant_type=Arg(Enum('password')), username=Arg(str), password=Arg(str)): """ Login user with username and password, returns token. """ assert grant_type username = username.strip() return auth.login(request.remote_addr, request.user_agent.string, username, password)
def main(): print('----选课系统首页----') result = login() if result: getattr(views, ROLE[result['role']])(result['user'])
def login(request, format=None): """Redirection vers le CAS pour obtenir un ticket""" return auth_view.login(request, format)
def entry_point(): print('in main') auth.login()