Esempio n. 1
0
    def post(self):
        tc = templates.Template()
        udb = db.Users()

        # get the email and validate it
        email = self.get_argument("email")
        email = email.lower().strip()
        user = udb.get_by_email(email)
        if not user:
            data = {
                "message": "This email is not registered"
            }
            html = unicode(tc.make_start_template(data))
            self.write(html)
            return

        # get the password and validate it
        password = self.get_argument("password")
        password = password.strip()
        password = crypt.convert_to_md5(password)
        if password != user['password']:
            data = {
                "message": "Wrong password!"
            }
            html = unicode(tc.make_start_template(data))
            self.write(html)
            return

        # make url:
        serialized = crypt.encrypt_userid(str(user['userid']))
        url = unicode("/welcome/" + serialized)

        # redirect to Welcome URL
        self.redirect(url)
Esempio n. 2
0
def signup(request):
    """
    create new user
    """
    if request.method == "POST":
        tc = templates.Template()
        udb = db.Users()

        # username
        username = request.POST["username"]
        username = to_unicode(username.strip())
        user = udb.get_by_username(username)
        if user:
            data = {
                "message": "Username already exists"
            }
            html = unicode(tc.make_start_template(request, data))
            return HttpResponse(html)

        # email
        email = request.POST["email"]
        email = to_unicode(email.lower().strip())
        user = udb.get_by_email(email)
        if user:
            data = {
                "message": "This email is already registered"
            }
            html = unicode(tc.make_start_template(request, data))
            return HttpResponse(html)

        # real name
        realname = request.POST["realname"]
        realname = to_unicode(realname.strip())

        # get the password and validate it
        password = request.POST["password"]
        password = to_unicode(password.strip())
        password = crypt.convert_to_md5(password)

        # create user
        userid = udb.insert(realname, username, email, password)
        if not userid:
            html = "OOPS!"
            return HttpResponse(html)

        # make url:
        serialized = crypt.encrypt_userid(str(userid))
        url = unicode("/welcome/" + serialized)

        # redirect to Welcome URL
        return redirect(url)
Esempio n. 3
0
    def post(self):
        tc = templates.Template()
        udb = db.Users()

        # username
        username = self.get_argument("username")
        username = to_unicode(username.strip())
        user = udb.get_by_username(username)
        if user:
            data = {
                "message": "Username already exists"
            }
            html = unicode(tc.make_start_template(data))
            self.write(html)
            return

        # email
        email = self.get_argument("email")
        email = to_unicode(email.lower().strip())
        user = udb.get_by_email(email)
        if user:
            data = {
                "message": "This email is already registered"
            }
            html = unicode(tc.make_start_template(data))
            self.write(html)
            return

        # real name
        realname = self.get_argument("realname")
        realname = to_unicode(realname.strip())

        # get the password and validate it
        password = self.get_argument("password")
        password = to_unicode(password.strip())
        password = crypt.convert_to_md5(password)

        # create user
        userid = udb.insert(realname, username, email, password)
        if not userid:
            self.write("OOPS!!")
            return

        # make url:
        serialized = crypt.encrypt_userid(str(userid))
        url = unicode("/welcome/" + serialized)

        # redirect to Welcome URL
        self.redirect(url)
Esempio n. 4
0
def start(request):
    """
    username and password template
    """
    if request.method == 'GET':
        tc = templates.Template()
        html = unicode(tc.make_start_template(request, data={}))
        return HttpResponse(html)

    elif request.method == 'POST':
        tc = templates.Template()
        udb = db.Users()

        # get the email and validate it
        email = request.POST["email"]
        email = email.lower().strip()
        user = udb.get_by_email(email)
        if not user:
            data = {
                "message": "This email is not registered"
            }
            html = unicode(tc.make_start_template(request, data))
            return HttpResponse(html)

        # get the password and validate it
        password = request.POST["password"]
        password = password.strip()
        password = crypt.convert_to_md5(password)
        if password != user['password']:
            data = {
                "message": "Wrong password!"
            }
            html = unicode(tc.make_start_template(request, data))
            return HttpResponse(html)

        # make url:
        serialized = crypt.encrypt_userid(str(user['userid']))
        url = unicode("/welcome/" + serialized)

        # redirect to Welcome URL
        return redirect(url)