Esempio n. 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)
                # 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 )
Esempio n. 2
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 )