示例#1
0
    def post(self):
        email = self.get_argument('email', '')
        password = self.get_argument('password', '')
        password_confirm = self.get_argument('password_confirm', '')

        error = False
        if not email or not password or not password_confirm:
            error = True

        if password != password_confirm:
            error = True

        if error == True:
            self.write('Missing a field or passwords do not match, all fields are required.<br />')
            self.write('Plase <a href="/register">try again.</a>')
            self.finish()
            return

        user = models.User.objects(email=email).first()
        if not user:

            user = models.User(email=email)
            user.password = util.hash_pwd(password)
            user.save()

            self.set_secure_cookie('user', str(user.id))
            self.redirect('/')
        else:
            self.write('User already exists.<br />')
            self.write('Plase <a href="/register">try again.</a>')
            self.finish()
示例#2
0
    def post(self):
        email = self.get_argument('email', '').lower()
        display_name = self.get_argument('display_name', '')
        password = self.get_argument('password', '')
        password_confirm = self.get_argument('password_confirm', '')
        url = self.get_argument('url', '').lower()
        public = True if self.get_argument('public', '') == 'yes' else False

        # check for general errors
        error = False
        if not email or not password or not password_confirm or not url:
            error = True
        if password != password_confirm:
            error = True
        if error:
            error_text = 'Missing a field or passwords do not match, all fields are required.'
            self.render('register.html', page_title='Register',
                        user=None, error=error_text)
            return

        # check that email hasn't already been used
        check_user = yield models.get_user_by_email(self.redis, email)
        if check_user:
            error_text = 'The email you tried already has an account. Please log in or register with a different email address.'
            self.render('register.html', page_title='Register',
                        user=None, error=error_text)
            return

        # make sure url is unique
        if url and not models.url_unique(url):
            error_text = 'A unique profile URL is required for public accounts!'
            self.render("register.html", page_title="Register",
                        user=None, error=error_text)

        new_user = models.User(email=email)
        new_user.password = util.hash_pwd(password)
        new_user.display_name = display_name
        new_user.url = url
        new_user.public = public
        new_user.save(self.redis)

        self.set_secure_cookie('user', str(new_user.id))
        self.tf.send({'users.registrations': 1}, lambda x: x)
        self.redirect('/')