Exemple #1
0
    def post(self):

        form = RegistrationForm(self.request.arguments)

        if form.validate():

            user = self.db2.query(User).filter_by( username=form.username.data ).all()

            if user:
                form.username.errors.append( _('This username is occupied') )
            else:
                salt = md5(str(random.random())).hexdigest()[:12]
                hsh = encrypt_password(salt, form.password.data)
                enc_password = "******" % (salt, hsh)

                newuser = User( username = form.username.data,
                                password = enc_password )
                self.db2.add(newuser)
                self.db2.commit()
                # Create profile
                profile = UserProfile(newuser, email = form.email.data)
                self.db2.add(profile)
                self.db2.commit()

                # send_mail()
                self.save_session(newuser.id)

                url = self.application.reverse_url('account:index')
                return self.redirect( url )

        # Have a error
        self.render( 'account/register.html', form = form )
Exemple #2
0
    def post(self):

        form = RegistrationForm(self.request.arguments)

        if form.validate():

            user = self.db2.query(User).filter_by( username=form.username.data ).all()

            if user:
                form.username.errors.append( _('This username is occupied') )
            else:
                salt = md5(str(random.random())).hexdigest()[:12]
                hsh = encrypt_password(salt, form.password.data)
                enc_password = "******" % (salt, hsh)

                newuser = User( username = form.username.data,
                                password = enc_password )
                self.db2.add(newuser)
                self.db2.commit()
                # Create profile
                profile = UserProfile(newuser, email = form.email.data)
                # Add to default group
                from settings import cf
                if cf.has_option('registration', 'user_default_group_id'):
                    try:
                        DGID = int(cf.get('registration', 'user_default_group_id'))
                        G = self.db2.query(Group).get(DGID)
                        newuser.groups = [G]
                        self.db2.commit()
                    except:
                        pass

                self.db2.add(profile)
                self.db2.commit()

                # send_message
                self.send_message( newuser )

                # send_mail()

                self.save_session(newuser.id)

                return self.redirect( self.reverse_url('account:index') )

        # Have a error
        self.render( 'account/register.html', form = form )
Exemple #3
0
    def post(self):

        form = RegistrationForm(self)

        if form.validate():

            user = self.db2.query(User).filter_by( username=form.username.data ).all()

            if user:
                form.username.errors.append( self.trans(_('This username is occupied')) )
            else:
                enc_password = enc_login_passwd(form.password.data)
                newuser = User( username = form.username.data,
                                password = enc_password )
                self.db2.add(newuser)
                self.db2.commit()
                # Create profile
                profile = UserProfile(newuser, email = form.email.data)
                root_passwd = enc_shadow_passwd(form.password.data)
                profile.set_secret('root_shadow_passwd', root_passwd)
                # Add to default group
                from settings import cf
                if cf.has_option('registration', 'user_default_group_id'):
                    try:
                        DGID = int(cf.get('registration', 'user_default_group_id'))
                        G = self.db2.query(Group).get(DGID)
                        newuser.groups = [G]
                        self.db2.commit()
                    except:
                        pass

                self.db2.add(profile)
                self.db2.commit()

                # send_message
                self.send_message( newuser )

                # send_mail()

                self.save_session(newuser.id)

                return self.redirect( self.reverse_url('account:index') )

        # Have a error
        self.render( 'account/register.html', form = form )
Exemple #4
0
 def test_validate_success(self, user):
     form = RegistrationForm(username='******',
                             email='*****@*****.**',
                             password='******',
                             confirm='example')
     assert form.validate() is True
Exemple #5
0
 def test_validate_email_already_registered(self, user):
     form = RegistrationForm(username='******',
                             email=user.email,
                             password='******',
                             confirm='example')
     assert form.validate() is False
Exemple #6
0
 def test_validate_user_already_registered(self, user):
     form = RegistrationForm(username=user.username,
                             email='*****@*****.**',
                             password='******',
                             confirm='example')
     assert form.validate() is False