Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    def post(self):
        data = tornado.escape.json_decode(self.request.body)
        KEYS = [
                'ALLOW_GUEST_DOWNLOAD',
                'ALLOW_GUEST_PUSH',
                'ALLOW_GUEST_READ',
                'ALLOW_REGISTER',
                'BOOK_NAMES_FORMAT',
                'FRIENDS',
                'FOOTER',
                'INVITE_CODE',
                'INVITE_MESSAGE',
                'INVITE_MODE',
                'MAX_UPLOAD_SIZE',
                'RESET_MAIL_CONTENT',
                'RESET_MAIL_TITLE',
                'SIGNUP_MAIL_CONTENT',
                'SIGNUP_MAIL_TITLE',
                'SOCIALS',
                'autoreload',
                'cookie_secret',
                'douban_apikey',
                'douban_baseurl',
                'douban_max_count',
                'site_title',
                'smtp_password',
                'smtp_server',
                'smtp_username',
                'static_host',
                'xsrf_cookies',
                ]

        args = loader.SettingsLoader()
        args.clear()

        for key, val in data.items():
            if key.startswith("SOCIAL_AUTH"):
                if key.endswith("_KEY") or key.endswith("_SECRET"):
                    args[key] = val
            elif key in KEYS:
                args[key] = val

        return self.save_extra_settings(args)