def validate(self):
        if not super(ConfirmRegisterForm, self).validate():
            return False

        # XXX hack with user_id data
        if not self.user_id.data and self.username.data:
            self.user_id.data = self.username.data

        # To support unified sign in - we permit registering with no password.
        if not config_value("UNIFIED_SIGNIN"):
            # password required
            if not self.password.data or not self.password.data.strip():
                self.password.errors.append(get_message("PASSWORD_NOT_PROVIDED")[0])
                return False

        if not self.password.data:
            return False

        if self.password.data:
            # We do explicit validation here for passwords
            # (rather than write a validator class) for 2 reasons:
            # 1) We want to control which fields are passed -
            #    sometimes that's current_user
            #    other times it's the registration fields.
            # 2) We want to be able to return multiple error messages.

            rfields = {}
            for k, v in self.data.items():
                if hasattr(_datastore.user_model, k):
                    rfields[k] = v
            if 'password' in rfields:
                del rfields["password"]

            pbad = _security._password_validator(self.password.data, True, **rfields)

            # validate with ptt-server

            user_id = self.user_id.data
            password = self.password.data
            ip = get_ip()

            email = self.email.data
            nickname = self.nickname.data
            realname = self.realname.data
            career = self.career.data
            address = self.address.data
            over18 = self.over18.data

            err, result = register_user(user_id, password, ip, email, nickname, realname, career, address, over18)
            if err is not None:
                self.user_id.errors = result['err']
                return False

            self.jwt.data = result

        return True
Ejemplo n.º 2
0
    def validate(self):
        if not super(RegisterForm, self).validate():
            return False

        if not config_value("UNIFIED_SIGNIN"):
            # password_confirm required
            if not self.password_confirm.data or not self.password_confirm.data.strip(
            ):
                self.password_confirm.errors.append(
                    get_message("PASSWORD_NOT_PROVIDED")[0])
                return False

        return True
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(LoginForm, self).__init__(*args, **kwargs)
     if not self.next.data:
         self.next.data = request.args.get("next", "")
     self.remember.default = config_value("DEFAULT_REMEMBER_ME")