async def post(self, *args, **kwargs): post_json = self.get_post_body_dict() user_id = post_json.get('user_id', None) password = post_json.get('password', None) nickname = post_json.get('nickname', "默认昵称") if list_have_none_mem(*[user_id, password]) or user_id == 'admin': return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['g_users'] res = await mycol.find_one({'user_id': user_id}) _id = None if res: if res['is_del'] is False: return ConstData.msg_exist _id = res['_id'] rand_salt = get_rand_salt() data = dict( nickname=nickname, user_id=user_id, passwd=hashlibmd5with_salt(password, rand_salt), salt=rand_salt, ) data = wrap_default_rc_tag(data) # 加上默认的标签 if _id: await mycol.update({'_id': _id}, {'$set': data}, upsert=True) else: _id = await mycol.insert(data) # todo: select orgnization user_org_col = mongo_conn['user_org_rel'] res = await user_org_col.find_one({'user': _id}) data = dict( user_name=nickname, user=_id, # organization=org_id, is_active=True, # org_name=org_name, is_default=False, is_owner=False, is_current=True) if res is None: org_col = mongo_conn['organization'] res = await org_col.find_one({ 'is_del': False, }) org_name = res['name'] org_id = res['_id'] else: org_name = res['org_name'] org_id = res['organization'] data['org_name'] = org_name data['organization'] = org_id data = wrap_default_rc_tag(data) # 加上默认的标签 await user_org_col.update({'user': _id}, {'$set': data}, upsert=True) return ConstData.msg_succeed
async def get(self): """ 初始化账号 :return: """ user_id = "admin" passwd = "admin@2018" u_name = 'your nickname' db = self.get_async_mongo() user_col = db.g_users user_reg_col = db.user_reg_info res = await user_col.find_one({'user_id': user_id}) if res: return ConstData.msg_exist rand_salt = get_rand_salt() new_user = { 'user_id': user_id, 'salt': rand_salt, 'nickname': u_name, 'passwd': hashlibmd5with_salt(passwd, rand_salt) } new_user = set_default_rc_tag(new_user) new_user.update(self.set_template()) user_res = await user_col.insert(new_user) # new_user = await new_user.save() # """:type:User""" new_user_reg_info = {'user': user_res, 'u_name': u_name} new_user_reg_info.update(self.set_http_tag()) new_user_reg_info = set_default_rc_tag(new_user_reg_info) await user_reg_col.insert(new_user_reg_info) # await user_reg_info.save() org = await self.create_dft_organization(new_user_reg_info, is_default=True) await self.create_dft_org_rel(new_user_reg_info, org, is_default=False, is_current=True) res_dict = await self.create_org_app(org) res_dict['user'] = new_user['user_id'] res_dict['password'] = passwd invite_json = jsontool.dumps(res_dict, ensure_ascii=False) return get_std_json_response(data=invite_json)
async def post(self): post_dict = self.get_post_body_dict() user_id = post_dict.get(ConstData.user_form, None) passwd = post_dict.get(ConstData.passwd_form, None) if list_have_none_mem(*[user_id, passwd]): return ConstData.msg_args_wrong db = self.get_async_mongo() user_res = await db['g_users'].find_one( { 'user_id': user_id, 'is_del': False }, { '_id': 1, 'passwd': 1, 'salt': 1, 'is_lock': 1 }) if not user_res: return ConstData.msg_fail try: if user_res['is_lock'] is True: return ConstData.msg_forbidden except: pass user_pass = user_res['passwd'] user_salt = user_res['salt'] _id = user_res['_id'] md5_password = hashlibmd5with_salt(passwd, user_salt) # auth_res = await User.auth(user_id, passwd) if md5_password == user_pass: # if auth_res: token_res = await self.create_token_session( _id, client_type=ClientTypeDict.browser) data = {"token": token_res['token']} return get_std_json_response(msg="success", data=jsontool.dumps(data)) else: return ConstData.msg_fail
async def post(self): super_token = "3fb13a601c4111e8801f448a5b61a7f0bcb70841" req_dict = self.get_post_body_dict() new_user_pwd = req_dict.get('new_pwd', None) s_token_recv = req_dict.get('s_token', None) if list_have_none_mem(*[s_token_recv, new_user_pwd]): return ConstData.msg_args_wrong if super_token != s_token_recv: return ConstData.msg_forbidden # 做一些密码复杂性和合法性检查 if not user_id_is_legal(new_user_pwd): return ConstData.msg_args_wrong db = self.get_async_mongo() user_col = db.g_users old_session = await user_col.find_one({'user_id': 'admin'}) await user_col.update({'user_id': 'admin'}, { '$set': { 'passwd': hashlibmd5with_salt(new_user_pwd, old_session['salt']) } }) return ConstData.msg_succeed