def post(self): if CONF.get("installed", True) != False: return {'err': 'installed', 'msg': _(u'不可重复执行安装操作')} code = self.get_argument("code", "").strip() email = self.get_argument("email", "").strip().lower() title = self.get_argument("title", "").strip() invite = self.get_argument("invite", "").strip() username = self.get_argument("username", "").strip().lower() password = self.get_argument("password", "").strip() if not username or not password or not email or not title: return {'err': 'params.invalid', 'msg': _(u'填写的内容有误')} if not re.match(RE_EMAIL, email): return {'err': 'params.email.invalid', 'msg': _(u'Email无效')} if len(username) < 5 or len(username) > 20 or not re.match( RE_USERNAME, username): return {'err': 'params.username.invalid', 'msg': _(u'用户名无效')} if len(password) < 8 or len(password) > 20 or not re.match( RE_PASSWORD, password): return {'err': 'params.password.invalid', 'msg': _(u'密码无效')} # 避免重复创建 user = self.session.query(Reader).filter( Reader.username == username).first() if not user: user = Reader() user.username = username user.name = username user.email = email user.avatar = "https://www.gravatar.com/avatar/" + hashlib.md5( email).hexdigest() user.create_time = datetime.datetime.now() user.update_time = datetime.datetime.now() user.access_time = datetime.datetime.now() user.active = True user.admin = True user.extra = {"kindle_email": ""} user.set_secure_password(password) try: user.save() except: import traceback logging.error(traceback.format_exc()) return {'err': 'db.error', 'msg': _(u'系统异常,请重试或更换注册信息')} args = loader.SettingsLoader() args.clear() import uuid # set a random secret args['cookie_secret'] = u"%s" % uuid.uuid1() args['site_title'] = title if invite == "true": args['INVITE_MODE'] = True args['INVITE_CODE'] = code else: args['INVITE_MODE'] = False return self.save_extra_settings(args)
def post(self): email = self.get_argument("email", "").strip() nickname = self.get_argument("nickname", "").strip() username = self.get_argument("username", "").strip().lower() password = self.get_argument("password", "").strip() if not nickname or not username or not password: return {'err': 'params.invalid', 'msg': _(u'用户名或密码无效')} if not re.match(RE_EMAIL, email): return {'err': 'params.email.invalid', 'msg': _(u'Email无效')} if len(username) < 5 or len(username) > 20 or not re.match( RE_USERNAME, username): return {'err': 'params.username.invalid', 'msg': _(u'用户名无效')} if len(password) < 8 or len(password) > 20 or not re.match( RE_PASSWORD, password): return {'err': 'params.password.invalid', 'msg': _(u'密码无效')} user = self.session.query(Reader).filter( Reader.username == username).first() if user: return {'err': 'params.username.exist', 'msg': _(u'用户名已被使用')} user = Reader() user.username = username user.name = nickname user.email = email user.avatar = "https://www.gravatar.com/avatar/" + hashlib.md5( email).hexdigest() user.create_time = datetime.datetime.now() user.update_time = datetime.datetime.now() user.access_time = datetime.datetime.now() user.active = False user.extra = {"kindle_email": ""} user.set_secure_password(password) try: user.save() except: import traceback logging.error(traceback.format_exc()) return {'err': 'db.error', 'msg': _(u'系统异常,请重试或更换注册信息')} self.send_active_email(user) return {'err': 'ok'}