Beispiel #1
0
def fb_login(request, onsuccess="/availabook/temp", onfail="/availabook/"):
    print "fb_login"
    user_id = str(request.POST.get("email"))
    pwd = str(request.POST.get("psw"))
    pwd_a = pwd
    firstname = request.POST.get("fn")
    lastname = request.POST.get("ln")
    age = request.POST.get("age")
    picture = request.POST.get("picture")
    print user_id, pwd, firstname, lastname, age, picture

    city = 'ny'
    zipcode = '10027'
    signup_handler = Signup(user_id, pwd, pwd_a, firstname, lastname, age, city, zipcode)
    signup_handler.add_picture(picture)

    user_db = Users(user_id, pwd)
    if user_db.verify_email() == False:
        print "account not exist"
        if not user_exists(user_id):
            user = User(username=user_id, email=user_id)
            user.set_password(pwd)
            user.save()
            authenticate(username=user_id, password=pwd)
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth_login(request, user)

            try:
                print "~~~~~~~~~"
                signup_handler.push_to_dynamodb()
                print "push success"
            except Exception as e:
                print (e)


            print str(request.user.username) + " is signed up and logged in: " + str(request.user.is_authenticated())
            return redirect(onsuccess)
        else:
            user=authenticate(username=user_id, password=pwd)
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth_login(request, user)
            print str(request.user.username) + " is signed up and logged in: " + str(request.user.is_authenticated())
            return redirect(onsuccess)
    else:
        print "dynamo has the user info", user_id, pwd
        user = authenticate(username=user_id, password=pwd)
        print user
        try:
            if user is not None:
                auth_login(request, user)
                print "redirecting"
                return redirect(onsuccess)
            else:
                print "user is none"
                return redirect(onfail)
        except Exception as e:
            print e
            return redirect(onfail)
Beispiel #2
0
def signup(request, onsuccess="/availabook/temp", onfail="/availabook/"):
    user_id = request.POST.get("email")
    pwd = request.POST.get("psw")
    pwd_a = request.POST.get("psw_a")
    firstname = request.POST.get("fn")
    lastname = request.POST.get("ln")
    age = request.POST.get("age")
    city = request.POST.get("city")
    zipcode = request.POST.get("zipcode")
    print user_id, pwd, pwd_a, firstname, lastname, age, city, zipcode

    signup_handler = Signup(user_id, pwd, pwd_a, firstname, lastname, age, city, zipcode)
    signup_handler.add_picture("https://s3.amazonaws.com/image-availabook/default")

    if pwd == pwd_a:
        if not user_exists(user_id):
            user = User(username=user_id, email=user_id)
            user.set_password(pwd)
            user.save()
            authenticate(username=user_id, password=pwd)
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth_login(request, user)
            print ("Successfully saving user information to Django sqlite.")
            try:
                signup_handler.push_to_dynamodb()
                print ("Successfully pushing user information to AWS Dynamodb.")
                print str(request.user.username) + " is signed up and logged in: " + str(request.user.is_authenticated())
                return redirect(onsuccess)
            except Exception as e:
                print (e)
                print ("Pushing user information to AWS Dynamodb failed! Please sign up again!")
                return HttpResponse("Error")
        else:
            user_db = Users(user_id, pwd)
            if user_db.verify_email() == False:
                print "Current user is already existed in Django sqlite, but not in AWS Dynamodb! Generally, sign up will fail. For debugging, maybe you should first delete this user from your django sqlite, clean the cache in browser and sign up again!"
                try:
                    signup_handler.push_to_dynamodb()
                    print ("Successfully pushing user information to AWS Dynamodb.")
                    if request.user.is_authenticated():
                        print str(request.user.username) + " is signed up and logged in: " + str(request.user.is_authenticated())
                        return redirect(onsuccess)
                    else:
                        print ("Sign up failed. Please debug following the instructions above!")
                        return HttpResponse("Error")
                except Exception as e:
                    print (e)
                    print ("Pushing user information to AWS Dynamodb failed! Please debug and sign up again!")
                    return HttpResponse("Error")
            else:
                print ("Current user is already existed in both Django sqlite and AWS Dynamodb! Please turn to log in first!")
                print ("If you still can't sign up and log in, for debugging, please delete this user from your django sqlite, clean the cache in browser and sign up again!")
                return HttpResponse("Error")
    else:
        print "Two input passwords inconsistent! Please sign up again!"
        return HttpResponse("Error")