def post(self): form = PasswordResetSendmailForm(self.request.arguments) if not form.validate(): raise HTTPError(404) response_data = {} email = form.email.data user = yield UserDocument.find_one({'email': email}) if not user: raise HTTPError(404) if not user['activated']: response_data.update({'error': '该账号尚未激活, 请先激活账号!'}) else: document = { 'uid': user["_id"], 'code': CodeDocument.generate_code(), 'expired_time': datetime.now() + timedelta(days=USER_SETTINGS['code_expired_after']) } yield CodeDocument.remove({"uid": user["_id"]}, multi=True) code_id = yield CodeDocument.insert(document) WriterManager.pub(MessageTopic.SEND_RESET_PASSWORD_EMAIL, code_id) self.finish(json.dumps(response_data))
def post(self): form = PasswordResetSendmailForm(self.request.arguments) if not form.validate(): raise HTTPError(404) response_data = {} email = form.email.data user = yield UserDocument.find_one({'email': email}) if not user: raise HTTPError(404) if not user['activated']: response_data.update({'error': '该账号尚未激活, 请先激活账号!'}) else: document = { 'uid': user["_id"], 'code': CodeDocument.generate_code(), 'expired_time': datetime.now() + timedelta( days=USER_SETTINGS['code_expired_after'] ) } yield CodeDocument.remove({"uid": user["_id"]}, multi=True) code_id = yield CodeDocument.insert(document) WriterManager.pub(MessageTopic.SEND_RESET_PASSWORD_EMAIL, code_id) self.write_json(response_data)
def post(self): form = AccountActiveSendmailForm(self.request.arguments) if not form.validate(): raise HTTPError(404) response_data = {} email = form.email.data user = yield UserDocument.find_one({'email': email}) if not user: raise HTTPError(404) if user['activated']: response_data.update({'error': '该账号已经激活!'}) else: document = { 'uid': user["_id"], 'code': CodeDocument.generate_code(), 'expired_time': datetime.now() + timedelta(days=USER_SETTINGS['code_expired_after']) } yield CodeDocument.remove({"uid": user["_id"]}, multi=True) code_id = yield CodeDocument.insert(document) WriterManager.pub(MessageTopic.SEND_ACTIVATION_EMAIL, code_id) self.write_json(response_data)
def post(self): response_data = {} form = RegisterForm(self.request.arguments) if form.validate(): name = form.name.data email = form.email.data password = form.password.data if (yield UserDocument.find_one({'name': name})): response_data["error"] = "用户名已被占用" if (yield UserDocument.find_one({"email": email})): response_data["error"] = "邮箱已被注册" if not response_data: password = yield UserDocument.encrypt_password(password) document = { 'email': email, 'name': name, 'password': password, 'user_type': "person", 'register_date': datetime.now() } try: user_id = yield UserDocument.insert(document) except: raise HTTPError(500) # 头像初始化 avatar = open( os.path.join(APPLICATION_SETTINGS['static_path'], 'img/default.jpg')) content = avatar.read() avatar.close() document = { 'name': 'default.jpg', 'upload_time': datetime.now(), 'content_type': 'jpeg', 'owner': DBRef(UserDocument.meta['collection'], ObjectId(user_id)), 'content': Binary(content), 'thumbnail50x50': Binary(content), 'thumbnail180x180': Binary(content) } yield AvatarDocument.insert(document) # 用户设置初始化 _ = yield OfficialProfileCoverDocument.get_profile_cover_list() profile_cover = random.sample(_, 1)[0] document = { 'user': DBRef(UserDocument.meta['collection'], ObjectId(user_id)), 'profile_cover': DBRef(OfficialProfileCoverDocument.meta['collection'], ObjectId(profile_cover['_id'])) } yield UserSettingDocument.insert(document) # Ejabberd注册 try: Ejabberd.register(user_id, password) except: pass # 给用户发送验证邮件 document = { 'uid': user_id, 'code': CodeDocument.generate_code(), 'expired_time': datetime.now() + timedelta(days=USER_SETTINGS['code_expired_after']) } code_id = yield CodeDocument.insert(document) WriterManager.pub(MessageTopic.SEND_ACTIVATION_EMAIL, code_id) response_data.update( {'success': '注册成功! 系统已经向你的注册邮箱发送了一封激活' '邮件, 请验证后登录!'}) else: for field in form.errors: response_data.update({'error': form.errors[field][0]}) break self.finish(json.dumps(response_data))
def post(self): response_data = {} form = RegisterForm(self.request.arguments) if form.validate(): name = form.name.data email = form.email.data password = form.password.data if (yield UserDocument.find_one({'name': name})): response_data["error"] = "用户名已被占用" if (yield UserDocument.find_one({"email": email})): response_data["error"] = "邮箱已被注册" if not response_data: password = yield UserDocument.encrypt_password(password) document = { 'email': email, 'name': name, 'password': password, 'user_type': "person", 'register_date': datetime.now() } try: user_id = yield UserDocument.insert(document) except: raise HTTPError(500) # 头像初始化 avatar = open(os.path.join( APPLICATION_SETTINGS['static_path'], 'img/default.jpg') ) content = avatar.read() avatar.close() document = { 'name': 'default.jpg', 'upload_time': datetime.now(), 'content_type': 'jpeg', 'owner': DBRef( UserDocument.meta['collection'], ObjectId(user_id) ), 'content': Binary(content), 'thumbnail50x50': Binary(content), 'thumbnail180x180': Binary(content) } yield AvatarDocument.insert(document) # 用户设置初始化 _ = yield OfficialProfileCoverDocument.get_profile_cover_list() profile_cover = random.sample(_, 1)[0] document = { 'user': DBRef( UserDocument.meta['collection'], ObjectId(user_id) ), 'profile_cover': DBRef( OfficialProfileCoverDocument.meta['collection'], ObjectId(profile_cover['_id']) ) } yield UserSettingDocument.insert(document) # Ejabberd注册 try: Ejabberd.register(user_id, password) except: pass # 给用户发送验证邮件 document = { 'uid': user_id, 'code': CodeDocument.generate_code(), 'expired_time': datetime.now() + timedelta( days=USER_SETTINGS['code_expired_after'] ) } code_id = yield CodeDocument.insert(document) WriterManager.pub(MessageTopic.SEND_ACTIVATION_EMAIL, code_id) response_data.update({ 'success': '注册成功! 系统已经向你的注册邮箱发送了一封激活' '邮件, 请验证后登录!' }) else: for field in form.errors: response_data.update({'error': form.errors[field][0]}) break self.write_json(response_data)