def get(self): form = AccountActiveForm(self.request.arguments) if not form: raise HTTPError(404) response_data = {} uid = form.uid.data code = form.code.data user = yield UserDocument.find_one({'_id': ObjectId(uid)}) if not user: raise HTTPError(404) code = yield CodeDocument.find_one({'uid': user["_id"], 'code': code}) if not code: raise HTTPError(404) if user['activated']: response_data.update({'error': '该账号已经激活!'}) elif code['expired_time'] < datetime.now(): response_data.update({'error': '激活码已失效! 请返回到登录界面重新发送激活码!'}) else: yield UserDocument.update({'_id': user['_id']}, {'$set': { 'activated': True }}) response_data.update({'error': '激活成功!'}) yield CodeDocument.remove({'_id': code['_id']}) self.render('user/template/feedback.html', response_data=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.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 get(self): form = AccountActiveForm(self.request.arguments) if not form: raise HTTPError(404) response_data = {} uid = form.uid.data code = form.code.data user = yield UserDocument.find_one({'_id': ObjectId(uid)}) if not user: raise HTTPError(404) code = yield CodeDocument.find_one({'uid': user["_id"], 'code': code}) if not code: raise HTTPError(404) if user['activated']: response_data.update({'error': '该账号已经激活!'}) elif code['expired_time'] < datetime.now(): response_data.update({ 'error': '激活码已失效! 请返回到登录界面重新发送激活码!' }) else: yield UserDocument.update( {'_id': user['_id']}, {'$set': {'activated': True}} ) response_data.update({'error': '激活成功!'}) yield CodeDocument.remove({'_id': code['_id']}) self.render('user/template/feedback.html', response_data=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 get(self): # 刷新失效 session_id = self.get_secure_cookie('sid') if session_id: session = self.session_manager.load_session(session_id) yield CodeDocument.remove({ 'uid': ObjectId(session["uid"]), 'code': session["code"] }) session.clear() self.clear_cookie("sid") form = PasswordResetGetForm(self.request.arguments) if not form: raise HTTPError(404) response_data = {} uid = form.uid.data code = form.code.data user = yield UserDocument.find_one({'_id': ObjectId(uid)}) if not user: raise HTTPError(404) code = yield CodeDocument.find_one({ 'uid': user["_id"], 'code': code }) if not code or datetime.now() > code['expired_time']: response_data.update({ 'error': '验证码已失效! 请返回到登录界面重新发送验证邮件!' }) if response_data: self.clear_cookie('sid') self.render( 'user/template/feedback.html', response_data=response_data ) else: session = self.session_manager.new_session() session["uid"] = uid session["code"] = code["code"] self.set_secure_cookie('sid', session.id, httponly=True) self.render('user/template/password-reset.html')
def post(self): form = PasswordResetPostForm(self.request.arguments) if not form: raise HTTPError(404) password = form.password.data session_id = self.get_secure_cookie('sid') if not session_id: raise HTTPError(404) self.session = self.session_manager.load_session(session_id) uid = self.session.get('uid') code = self.session.get('code') if not uid or not code: raise HTTPError(404) code = yield CodeDocument.find_one({ 'uid': ObjectId(uid), 'code': code }) if not code: raise HTTPError(404) user = yield UserDocument.find_one({'_id': ObjectId(uid)}) if not user: raise HTTPError(404) password = yield UserDocument.encrypt_password(password) yield UserDocument.update({'_id': user["_id"]}, {'$set': { 'password': password }}) yield CodeDocument.remove({'_id': ObjectId(code['_id'])}) try: Ejabberd.unregister(user['_id']) Ejabberd.register(user['_id'], password) except: pass self.session.clear() self.clear_cookie('sid') self.finish()
def post(self): form = PasswordResetPostForm(self.request.arguments) if not form: raise HTTPError(404) password = form.password.data session_id = self.get_secure_cookie('sid') if not session_id: raise HTTPError(404) self.session = self.session_manager.load_session(session_id) uid = self.session.get('uid') code = self.session.get('code') if not uid or not code: raise HTTPError(404) code = yield CodeDocument.find_one({ 'uid': ObjectId(uid), 'code': code }) if not code: raise HTTPError(404) user = yield UserDocument.find_one({'_id': ObjectId(uid)}) if not user: raise HTTPError(404) password = yield UserDocument.encrypt_password(password) yield UserDocument.update( {'_id': user["_id"]}, {'$set': {'password': password}} ) yield CodeDocument.remove({'_id': ObjectId(code['_id'])}) try: Ejabberd.unregister(user['_id']) Ejabberd.register(user['_id'], password) except: pass self.session.clear() self.clear_cookie('sid') self.finish()
def get(self): # 刷新失效 session_id = self.get_secure_cookie('sid') if session_id: session = self.session_manager.load_session(session_id) yield CodeDocument.remove({ 'uid': ObjectId(session["uid"]), 'code': session["code"] }) session.clear() self.clear_cookie("sid") form = PasswordResetGetForm(self.request.arguments) if not form: raise HTTPError(404) response_data = {} uid = form.uid.data code = form.code.data user = yield UserDocument.find_one({'_id': ObjectId(uid)}) if not user: raise HTTPError(404) code = yield CodeDocument.find_one({'uid': user["_id"], 'code': code}) if not code or datetime.now() > code['expired_time']: response_data.update({'error': '验证码已失效! 请返回到登录界面重新发送验证邮件!'}) if response_data: self.clear_cookie('sid') self.render('user/template/feedback.html', response_data=response_data) else: session = self.session_manager.new_session() session["uid"] = uid session["code"] = code["code"] self.set_secure_cookie('sid', session.id, httponly=True) self.render('user/template/password-reset.html')