async def post(self): username = self.post_data.get('username', '') password = self.post_data.get('password', '') try: libs.validator.username(username) libs.validator.password(password) except libs.validator.ValidationError as e: self.send_to_client(-1, message=e.__str__()) return if username == Config().password_login.get( 'username') and password == Config().password_login.get( 'password'): pb_account = await AccountServer().get_account_by_id( account_id=int(Config().password_login.get('account_id')), app_id=self.app_id_int64, request_id=self.request_id) account = Account(pb_account) # get account userinfo if account.status == pbaccount_pb2.STATUS_ACTIVATED: pb_userinfo = await AccountServer().get_userinfo( account.account_id, app_id=self.app_id_int64, request_id=self.request_id) await account.set_userinfo(pb_userinfo) self.send_to_client(0, message='登陆成功', response=account.dump()) else: self.send_to_client(-1, message='登录状态异常') else: self.send_to_client(-1, message='账号或密码错误')
async def post(self): code = self.post_data.get('code', None) if not code: raise HTTPError(400, "code为空?", reason="code为空?") # login to fetch openid/session_key/unionid login_response = await WxCCServer().miniprogram_login( code, self.request_id) if login_response is None: raise HTTPError(500, "登录微信服务器出错", reason="登录微信服务器出错") # get account exists_wechat = await AccountServer().exists_partner_wechat( identifier=login_response.unionid, app_id=self.app_id_int64, request_id=self.request_id) if not exists_wechat: # create account pb_account = await AccountServer().create_account_by_partner( partner=pbaccount_pb2.PARTNER_WECHAT, identifier=login_response.unionid, origin_data={}, app_id=self.app_id_int64, request_id=self.request_id) # 分配空间 await MembershipServer().set_total_storage_change( account_id=pb_account.account_id, changed_value=Config().membership.get("register_default_size"), title=Config().membership.get("register_default_title"), details=Config().membership.get("register_default_details"), request_id=self.request_id) else: pb_account = await AccountServer().auth_partner_account( identifier=login_response.unionid, app_id=self.app_id_int64, request_id=self.request_id) # set account pair to wxcc server await WxCCServer().miniprogram_set_account_pair( account_id=pb_account.account_id, login_response=login_response, request_id=self.request_id) account = Account(pb_account) pb_userinfo = await AccountServer().get_userinfo( account.account_id, app_id=self.app_id_int64, request_id=self.request_id) await account.set_userinfo(pb_userinfo) self.send_to_client(0, message='登录成功', response=account.dump())
async def post(self): mobile = self.post_data.get('mobile', '') smscode = self.post_data.get('smscode', '') errors = self._check_input({"mobile": mobile, "smscode": smscode}) if errors: err = '' for item, er in errors.items(): err = er break self.send_to_client(error_id=error.input_error.id, message=err) return # Check smscode mobile_smscode = rd.redis_get('verify:{}'.format(mobile)) if mobile_smscode: mobile_smscode = mobile_smscode.decode() if mobile_smscode != smscode: self.send_to_client(-1, '登陆验证码错误') return # Exists Mobile exists_account_already = False try: exists_account_already = await AccountServer( ).exists_account_by_mobile(mobile, request_id=self.request_id) except grpc.RpcError as e: self.send_to_client(error_id=500, message='服务器内部错误,请联系管理员确认') return pb_account = None if not exists_account_already: # not exists, create account pb_account = await AccountServer().create_account( mobile=mobile, country_code="86", app_id=self.app_id_int64, request_id=self.request_id) # 分配空间 result = await MembershipServer().set_total_storage_change( account_id=pb_account.account_id, changed_value=Config().membership.get("register_default_size"), title=Config().membership.get("register_default_title"), details=Config().membership.get("register_default_details"), request_id=self.request_id) else: # exists, get the account pb_account = await AccountServer().get_account_by_mobile( mobile=mobile, country_code="86", app_id=self.app_id_int64, request_id=self.request_id) # make Account Model if pb_account is None: self.send_to_client(error_id=500, message='服务器内部错误,请联系管理员确认') return account = Account(pb_account) # get account userinfo if account.status == pbaccount_pb2.STATUS_ACTIVATED: rd.redis_del('verify:{}'.format(mobile)) pb_userinfo = await AccountServer().get_userinfo( account.account_id, app_id=self.app_id_int64, request_id=self.request_id) await account.set_userinfo(pb_userinfo) self.send_to_client(0, message='登陆成功', response=account.dump()) return status_error = {0: "未知状态的账号", 2: "未激活账号", 3: "锁定并暂停账号或封号", 4: "账号已注销"} self.send_to_client(-1, message=status_error.get(account.status))
async def post(self): code = self.post_data.get('code', None) if not code: raise HTTPError(400, "code为空?", reason="code为空?") # fetch userinfo from wechat server wx_pb_userinfo = await WxCCServer().open_app_login( code, self.request_id) if wx_pb_userinfo is None: raise HTTPError(500, "登录微信服务器出错", reason="登录微信服务器出错") wx_userinfo_dict = MessageToDict(wx_pb_userinfo, including_default_value_fields=True, preserving_proto_field_name=True, use_integers_for_enums=True) # get account exists_wechat = await AccountServer().exists_partner_wechat( identifier=wx_pb_userinfo.unionid, app_id=self.app_id_int64, request_id=self.request_id) if not exists_wechat: # create account pb_account = await AccountServer().create_account_by_partner( partner=pbaccount_pb2.PARTNER_WECHAT, identifier=wx_pb_userinfo.unionid, origin_data=wx_userinfo_dict, app_id=self.app_id_int64, request_id=self.request_id) # 分配空间 await MembershipServer().set_total_storage_change( account_id=pb_account.account_id, changed_value=Config().membership.get("register_default_size"), title=Config().membership.get("register_default_title"), details=Config().membership.get("register_default_details"), request_id=self.request_id) else: # auth the wechat account pb_account = await AccountServer().auth_partner_account( wx_pb_userinfo.unionid, app_id=self.app_id_int64, request_id=self.request_id) # update partner info await AccountServer().update_partner_account_origin_data( pb_account.auth_token, pbaccount_pb2.PARTNER_WECHAT, wx_pb_userinfo.unionid, wx_userinfo_dict, self.app_id_int64, self.request_id) # set account pair to wxcc server await WxCCServer().open_app_set_account_pair( openid=wx_pb_userinfo.openid, account_id=pb_account.account_id, request_id=self.request_id) # get userinfo pb_current_userinfo = await AccountServer().get_userinfo( pb_account.account_id, self.app_id_int64, self.request_id) # update user info params_people = dict() if not pb_current_userinfo.nickname: params_people["nickname"] = wx_pb_userinfo.nickname if not pb_current_userinfo.gender: params_people["gender"] = str(wx_pb_userinfo.gender) if params_people: await AccountServer().update_user_info( account_id=pb_account.account_id, params=params_people, app_id=self.app_id_int64, request_id=self.request_id) if not pb_current_userinfo.avatar: # generate avatar filename zid = await ZIDServer().generate(self.request_id) # upload filename, err = await backend.backend_user_media.transmit_wechat_avatar( zid=zid, remote_url=wx_pb_userinfo.avatar) if not err and filename: # update avatar await AccountServer().update_user_avatar( account_id=pb_account.account_id, app_id=self.app_id_int64, request_id=self.request_id, avatar=filename) account = Account(pb_account) pb_userinfo = await AccountServer().get_userinfo( pb_account.account_id, self.app_id_int64, self.request_id) await account.set_userinfo(pb_userinfo) self.send_to_client(0, message='登录成功', response=account.dump())