Esempio n. 1
0
    def processInput(self, request):
        print "%s%s %s%s" % (settings.color.RED, __name__, inspect.stack()[0][3], settings.color.ENDC)
        self.makeHtml()
        stop = False
        response = []

        print '%s%s %s%s' % (settings.color.RED, request, type(request), settings.color.ENDC)
        print '%s%s%s' % (settings.color.RED, request.args, settings.color.ENDC)

        if request.args:
            for key in sorted(request.args.iterkeys()):
                print key
                value = request.args.get(key)
                self.args.append(value[0])

        print self.args
        if self.args:
            if not self.args[0]:
                stop = True
                response.append('Username not entered')

            elif not re.match('^[\w-]+$', self.args[0]):
                stop = True
                response.append('Non-alphanumeric username entered')

            if not self.args[1]:
                stop = True
                response.append('Password not entered')

            elif not re.match('^[\w-]+$', self.args[1]):
                stop = True
                response.append('Non-alphanumeric password entered')

        else:
            stop = True

        user = []
        if not stop:
            user = usersModule.getOne(self.args[0])

            if self.args[2] == 'Register':
                if user:
                    stop = True
                    response.append('Username taken')

                else:
                    usersModule.create(self.args[0], self.args[1])
                    response.append('Registration successful')

        self.formResponse = ''
        if response:
            self.formResponse += '<table>'
            if stop:
                self.formResponse += '<tr bgcolor="#FF0000"><td>%s</td></tr>' % response
            else:
                self.formResponse += '<tr bgcolor="#00FF00"><td>%s</td></tr>' % response
            self.formResponse += '</table>'
        self.html = self.formResponse + self.html
Esempio n. 2
0
    def processInput(self, request):
        stop = False
        response = []

        try:
            print '%s%s%s' % (settings.color.RED, request.args,
                              settings.color.ENDC)
            button = request.args.get('button')
            username = request.args.get('username')
            password = request.args.get('password')

            button = button[0]
            username = username[0]
            password = password[0]

            if not username:
                stop = True
                response.append('Username not entered')

            elif not re.match('^[\w-]+$', username):
                stop = True
                response.append('Non-alphanumeric username entered')

            if not password:
                stop = True
                response.append('Password not entered')

            elif not re.match('^[\w-]+$', password):
                stop = True
                response.append('Non-alphanumeric password entered')

            if not stop:
                user = usersModule.getOne(username)
                if button == 'Register':
                    if user:
                        stop = True
                        response.append('Username taken')

                    else:
                        usersModule.create(username, password)
                        response.append('Registration successful')
                        print '%snew_user created%s' % (settings.color.YELLOW,
                                                        settings.color.ENDC)

                if button == 'Login':
                    if user:
                        if encryptor.checkPassword(user[2], password):
                            sessions.manager.setUserId(request, user[0])
                            response.append('Login sussessful')
                            print '%s%s: logged in from %s%s' % (
                                settings.color.YELLOW, user[0],
                                request.getClientIP(), settings.color.ENDC)

                        else:
                            stop = True
                            response.append('Invalid password entered')
                            print '%s%s: invalid password entered%s' % (
                                settings.color.YELLOW, user[0],
                                settings.color.ENDC)

                    else:
                        stop = True
                        response.append('Invalid username entered')
        except:
            pass

        if response:
            self.html += '<table>'
            if stop:
                self.html += '<tr bgcolor="#FF0000"><td>%s</td></tr>' % response
            else:
                self.html += '<tr bgcolor="#00FF00"><td>%s</td></tr>' % response
            self.html += '</table>'