コード例 #1
0
    def _post_path_register(self, name, account, password, confirm_password):
        if self.current_user:
            return
        if not check_email_addr(account):
            self.error_write("register_email_format_wrong")
            return
        if not password_check(password):
            self.error_write("register_password_format_wrong")
            return
        if password != confirm_password:
            self.error_write("register_confirm_password_wrong")
            return

        same_name_user = db.users.find_one({"account": account})
        if same_name_user:
            self.error_write("register_same_email")
            return

        id = str(uuid.uuid4().hex)
        result = db.users.insert({
            "_id": id,
            "name": name,
            "account": account,
            "password": encrypt_password(password),
        })

        if result:
            self.change_session({"uid": id})
            self.fresh_current_user()

            self.write({"status": 0, "dscp": "您已经完成注册!"})

        self.finish()
コード例 #2
0
ファイル: handlers.py プロジェクト: abc950309/autoclave
    def post(self, password, confirm_password, layout, says, pair_code):
        if not self.current_user.email_confirmed:
            return self.redirect("/Setting?show_type=warning&show_text=您需要确认邮箱,才可更改设置。")

        for line in [password, layout, says]:
            if line:
                break
        else:
            self.error_write("setting_arg_missing")
            return

        self.set_dict = {}

        if password:
            if password != confirm_password:
                self.error_write("setting_confirm_password_wrong")
                return
            if not password_check(password):
                self.error_write("setting_password_format_wrong")
                return
            self.set_dict["password"] = encrypt_password(password)

        if layout and (not self.current_user.layout or layout != self.current_user.layout._id):
            if not db.layouts.find_one({"_id": layout}):
                self.error_write("setting_no_layout")
                return
            self.set_dict["layout"] = DBRef("layouts", layout)

        if says and (not self.current_user.says or says != self.current_user.says):
            self.set_dict["says"] = says

        if pair_code:
            if self.current_user.pair:
                self.error_write("setting_double_pair")
                return
            self.dealed_pair_code = models.PairCode.get4db(db.pair_codes.find_one({"code": pair_code}))
            if not self.dealed_pair_code:
                self.error_write("setting_bad_pair")
                return
            self.set_dict["pair"] = self.dealed_pair_code["pair_to"]

        if len(self.set_dict) == 0:
            self.error_write("setting_arg_missing")
            return

        self.result = db.users.update_one(
            {"_id": self.current_user._id}, {"$set": self.set_dict, "$currentDate": {"lastModified": True}}
        )
        self.fresh_current_user()

        if self.ajax_flag:
            self.write({"status": 0})
        else:
            return self.redirect("/Setting?show_type=success&show_text=设置成功!")
コード例 #3
0
    def post(self, password, confirm_password, layout, says, pair_code):
        if not self.current_user.email_confirmed:
            return self.redirect(
                "/Setting?show_type=warning&show_text=您需要确认邮箱,才可更改设置。")

        for line in [password, layout, says]:
            if line:
                break
        else:
            self.error_write("setting_arg_missing")
            return

        self.set_dict = {}

        if password:
            if password != confirm_password:
                self.error_write("setting_confirm_password_wrong")
                return
            if not password_check(password):
                self.error_write("setting_password_format_wrong")
                return
            self.set_dict["password"] = encrypt_password(password)

        if layout and (not self.current_user.layout
                       or layout != self.current_user.layout._id):
            if not db.layouts.find_one({"_id": layout}):
                self.error_write("setting_no_layout")
                return
            self.set_dict["layout"] = DBRef("layouts", layout)

        if says and (not self.current_user.says
                     or says != self.current_user.says):
            self.set_dict["says"] = says

        if pair_code:
            if self.current_user.pair:
                self.error_write("setting_double_pair")
                return
            self.dealed_pair_code = models.PairCode.get4db(
                db.pair_codes.find_one({"code": pair_code}))
            if not self.dealed_pair_code:
                self.error_write("setting_bad_pair")
                return
            self.set_dict["pair"] = self.dealed_pair_code["pair_to"]

        if len(self.set_dict) == 0:
            self.error_write("setting_arg_missing")
            return

        self.result = db.users.update_one({"_id": self.current_user._id}, {
            "$set": self.set_dict,
            "$currentDate": {
                "lastModified": True
            }
        })
        self.fresh_current_user()

        if self.ajax_flag:
            self.write({
                "status": 0,
            })
        else:
            return self.redirect("/Setting?show_type=success&show_text=设置成功!")
コード例 #4
0
ファイル: handlers.py プロジェクト: abc950309/autoclave
    def _post_path_register(self, name, account, password, confirm_password):
        if self.current_user:
            return
        if not check_email_addr(account):
            self.error_write("register_email_format_wrong")
            return
        if not password_check(password):
            self.error_write("register_password_format_wrong")
            return
        if password != confirm_password:
            self.error_write("register_confirm_password_wrong")
            return

        same_name_user = db.users.find_one({"account": account})
        if same_name_user:
            self.error_write("register_same_email")
            return

        id = str(uuid.uuid4().hex)
        result = db.users.insert({"_id": id, "name": name, "account": account, "password": encrypt_password(password)})

        if result:
            self.change_session({"uid": id})
            self.fresh_current_user()

            self.write({"status": 0, "dscp": "您已经完成注册!"})

        self.finish()