示例#1
0
def register(request):
    u = request.POST['user']
    p = request.POST['pass']
    user = Member(username=u, password=p)
    user.save()
    context = {'appname': appname, 'username': u}
    return render(request, 'social/user-registered.html', context)
示例#2
0
def email(request):
    if 'email' in request.POST:
        e = request.POST['email']

        try:
            generated_pass = my_random_string(20)
            member = Member.objects.get(email=e)
            u = Member.objects.get(pk=member)
            user = Member(username=u, password=generated_pass, email=e)
            user.save()

            connection = mail.get_connection()
            connection.open()
            body = 'http://127.0.0.1/social/profile/#tab_change_password'
            email1 = mail.EmailMessage('Facemagazine', 'You have requested for password change. This is your temporary password, once loggedin please change your password. You can update your password by visiting this link -> http://127.0.0.1/social/profile/#tab_change_password <-   '+generated_pass,
                                       '*****@*****.**', [e], connection=connection)
            email1.send() # Send the email
            connection.close()

            template = loader.get_template('social/index.html')
            context = RequestContext(request, {
                    'appname': appname,
                    'login_status': 'Thank you, we have sent you email to reset your password.',
                })
            return HttpResponse(template.render(context))
        except Member.DoesNotExist:
            template = loader.get_template('social/index.html')
            context = RequestContext(request, {
                    'appname': appname,
                    'login_status': 'member does not exist',
                })
            return HttpResponse(template.render(context))
示例#3
0
def register(request):
    #get posted requests
    u = request.POST['user']
    p = request.POST['pass']
    e = request.POST['Email']

    try:
        #try to aquire the user
        member = Member.objects.get(pk=u)
    except Member.DoesNotExist:
        #it no existence then None is assigned to member
        member = None

    try:
        #checks if email already exists
        email_duplicate_check = Member.objects.get(email=e)
    except:
        #None assigned if email found
        email_duplicate_check = None

    if member is not None or email_duplicate_check is not None:
        return render(request, "social/username_taken.html", RequestContext(request, locals()))
    else:
        # return render(request, "social/username_free.html", RequestContext(request, locals()))
        user = Member(username=u, password=p, email=e)
        user.save()
        template = loader.get_template('social/user-registered.html')
        context = RequestContext(request, {
            'appname': appname,
            'username': u
            })
        return HttpResponse(template.render(context))
示例#4
0
def register(request):
    u = request.POST['user']
    p = request.POST['pass']
    user = Member(username=u, password=p)
    user.save()
    template = loader.get_template('social/user-registered.html')
    context = RequestContext(request, {'appname': appname, 'username': u})
    return HttpResponse(template.render(context))
示例#5
0
文件: views.py 项目: jbprj15/WebCW1
def register(request):
    u = request.POST["user"]
    p = request.POST["pass"]
    user = Member(username=u, password=p)
    user.save()
    template = loader.get_template("social/user-registered.html")
    context = RequestContext(request, {"appname": appname, "username": u})
    return HttpResponse(template.render(context))
示例#6
0
def register(request):
    u = request.POST['user']
    p = request.POST['pass']
    user = Member(username=u, password=p)
    user.save()
    return render(request, 'social/user-registered.html', {
        'appname': appname,
        'username' : u
        })
示例#7
0
def register(request):
    u = request.POST['user']
    p = request.POST['pass']
    hasher = PBKDF2PasswordHasher()
    p = hasher.encode(password=p, salt='salt', iterations=50000)
    user = Member(username=u, password=p, date=timezone.now())
    user.save()
    template = loader.get_template('social/user-registered.html')
    context = RequestContext(request, {'appname': appname, 'username': u})
    return HttpResponse(template.render(context))
示例#8
0
def register(request):
    u = request.POST['user']
    p = request.POST['pass']
    user = Member(username=u, password=p)
    user.save()
    template = loader.get_template('social/user-registered.html')
    context = RequestContext(request, {
        'appname': appname,
        'username' : u
        })
    return HttpResponse(template.render(context))
示例#9
0
def register(request):
	if 'user' in request.POST:
		u = request.POST['user']
		p = request.POST['pass']
		try:
			member = Member.objects.get(pk=u)
			message = "User " + u + " already exist"
			template = loader.get_template('social/signup.html')
			context = RequestContext(request, {
        	'appname': appname,
        	'username' : u,
        	'message' : message
        	})
        	except Member.DoesNotExist:
        		template= loader.get_template('social/user-registered.html')
        		user = Member(username=u, password=p)
        		user.save()
        		context = RequestContext(request, {
        		'appname': appname,
        		'username' : u
        		})
		return HttpResponse(template.render(context))
示例#10
0
def register(request):
    u = request.POST['user']
    p = request.POST['pass']

    template = loader.get_template('social/username_taken.html')
    context = RequestContext(request, {
                'appname': appname
                    })

    if Member.objects.filter(pk=u).exists() : # if the username exists then go the the username taken page
        return HttpResponse(template.render(context))

    else:
        hasher = PBKDF2PasswordHasher() #using PBKDF2 algorithm to hash
        hashedp = hasher.encode(password= p, salt='salt', iterations = 50000) #hashing password
        user = Member(username=u, password=hashedp)
        user.save()

    template = loader.get_template('social/user-registered.html')
    context = RequestContext(request, {
        'appname': appname,
        'username' : u
     })
    return HttpResponse(template.render(context))
示例#11
0
def change_pass(request):
    #get current loggedin user
    username = request.session['username']
    user = Member.objects.get(pk=username)

    notify = my_random_string(1)
    #'Please ensure fields are not empty'

    #get password and email stored in the database
    oldpass_inDB = user.password
    oldemail_inDB = user.email

    #get password and email from user input via the front end
    if 'oldpass' in request.POST:
        oldpass = request.POST['oldpass']

    if 'newpass' in request.POST:
        newpass = request.POST['newpass']

    if 'confirmpass' in request.POST:
        confirmpass = request.POST['confirmpass']

    if 'changeemail' in request.POST:
        changeemail = request.POST['changeemail']

    #if user leaves the oldpass blank, then no update is saved to the database
    if oldpass == oldpass_inDB:
        if newpass == confirmpass:
            if newpass != '':
                if changeemail == oldemail_inDB:
                    user = Member(username=user, password=newpass, email=oldemail_inDB)
                    user.save()
                    notify = my_random_string(2)
                    # 'successfully updated your password'
                else:
                    if changeemail != '':
                        user = Member(username=user, password=newpass, email=changeemail)
                        user.save()
                        notify = my_random_string(3)
                        #'successfully updated your password and email'
                    else:
                        notify = my_random_string(4)
                        #'please input email'
            else:
                notify = my_random_string(5)
                #'please input password'
        else:
            notify = my_random_string(6)
            #'please ensure confirm password matches with new password'
    else:
        if changeemail == oldemail_inDB:
             notify = my_random_string(7)
        #     #'Please ensure your old password matches with your input'
        else:
            if changeemail != '':
                user = Member(username=user, password=oldpass_inDB, email=changeemail)
                user.save()
                notify = my_random_string(8)
                #'successfully updated your email'
            else:
                notify = my_random_string(9)
                #'please input fields are not empty'

    return redirect('/social/profile/?='+notify+'#tab_change_password')