Esempio n. 1
0
def signup(request):  #sign up page. url/signup/
    if request.method == 'GET':
        return render_to_response(
            'signup.html', RequestContext(request))  #if get display page
    else:
        name = request.POST.get('username')
        password = request.POST.get('password')
        mail = request.POST.get('mail')
        phone = request.POST.get('number')  #extraxt data from form fields
        new_user = User(user_name=name,
                        user_password=password,
                        mail_id=mail,
                        phonenumber=phone)  #pass data to object
        new_user.save()  #commit data to database
        try:

            ses = Session.objects.latest('id')
            #get the highest session id
            val = ses.id + 1
        except Session.DoesNotExist:
            val = 1
        newSession = Session(id=val,
                             user_id=new_user.id,
                             login='******',
                             mcount=0,
                             bcount=0)
        newSession.save()
        #create a new session for the user
        return HttpResponseRedirect('/%s/initial' % val)
Esempio n. 2
0
def startPage(request):
    if request.method == 'GET':
        if 'e' in request.GET:
            return render_to_response('start.html', {'error': '1'},
                                      context_instance=RequestContext(request))
            #if error pass error code
        else:
            return render_to_response('start.html', {},
                                      context_instance=RequestContext(request))
        #if no error display page
    else:
        userName = request.POST.get('user_name')
        #extract data from text field
        password = request.POST.get('password')
        try:
            user = User.objects.get(user_name=userName)
            #search for user with given user name
        except User.DoesNotExist:
            return HttpResponseRedirect('/?e=1')
            #if no such user set error code to 1
        if password == user.user_password:
            #if user name and password exist authenticate user
            try:

                ses = Session.objects.latest('id')
                #get the highest session id
                val = ses.id + 1
            except Session.DoesNotExist:
                val = 1
            newSession = Session(id=val,
                                 user_id=user.id,
                                 login='******',
                                 mcount=0,
                                 bcount=0)
            newSession.save()
            #create a new session for the user
            return HttpResponseRedirect('/%s/home' %
                                        val)  #set url to /session id/home
        return HttpResponseRedirect('/?e=0')