def _make_user_from_registration(reg): ## check to see if already registered if get_user_by_email(reg.email): user = get_user_by_email(reg.email) return user user = authmodels.User() user.username = make_username(reg.email) ## intentionally a dupe, since we dont have a username. WE MUST be sure not to overflow it (max_chat is default 30) user.email = reg.email user.first_name = joeuser_name user.set_password(reg.password) user.save() ## handle couhes reg if (reg.couhes): ## assert nonblank(reg.first_name) and nonblank(reg.last_name), "Couhes requires non blank first and last names" user.first_name = reg.first_name user.last_name = reg.last_name user.save() ## now make couhes consetnform cc = CouhesConsent() cc.owner = user cc.signed_date = reg.when cc.save() return user
def _make_user_from_registration(reg): ## check to see if already registered if get_user_by_email(reg.email): user = get_user_by_email(reg.email) return user user = authmodels.User(); user.username = make_username(reg.email); ## intentionally a dupe, since we dont have a username. WE MUST be sure not to overflow it (max_chat is default 30) user.email = reg.email; user.first_name = joeuser_name; user.set_password(reg.password); user.save(); ## handle couhes reg if (reg.couhes): ## assert nonblank(reg.first_name) and nonblank(reg.last_name), "Couhes requires non blank first and last names" user.first_name = reg.first_name; user.last_name = reg.last_name; user.save(); ## now make couhes consetnform cc = CouhesConsent() cc.owner = user; cc.signed_date = reg.when; cc.save() return user
def changepassword(request): ## POST view, parameters cookie and password cookie = request.POST['cookie'] password = request.POST['password'] assert cookie != None and len(password) > 0, "Cookie cannot be null" assert password != None and len(password) > 0, "Password cannot be null" matching_requests = ChangePasswordRequest.objects.filter(cookie=cookie) if len(matching_requests) == 0: response = HttpResponse( "Sorry, I did not know about your request to change your password.", "text/html") response.status_code = 405 logevent(request, 'changepassword', 405, repr(request)) return response reqobject = matching_requests[0] matching_user = get_user_by_email(reqobject.username) if not matching_user: response = HttpResponse( "Sorry, I did not know about the user you are asking about: %s " % repr(reqobject.username), "text/html") response.status_code = 404 logevent(request, 'changepassword', 404, repr(request)) return response matching_user.set_password(password) matching_user.save() reqobject.delete() response = render_to_response( 'jv3/confirmuser.html', { 'message': "Your password hs been updated successfully, %s." % matching_user.email }) logevent(request, 'changepassword', 200, repr(cookie)) return response
def changepassword_request(request): ## GET view, parameter username email = request.GET['username'] matching_user = get_user_by_email(email) if not matching_user: response = HttpResponse( "Unknown user, did you register previously for List.it under a different email address?", "text/html") response.status_code = 404 logevent(request, 'changepassword_request', 404, repr(request)) return response req = makeChangePasswordRequest(email) send_mail('Confirm List.it change password request', gen_confirm_change_password_email(req), '*****@*****.**', (matching_user.email, ), fail_silently=False) response = render_to_response( 'jv3/changepassword_request.html', {'message': "(I just sent email to you at %s)" % matching_user.email}) logevent(request, 'changepassword_request', 200, repr(( email, req.cookie, ))) response.status_code = 200 return response
def userexists(request): email = request.GET['email'] if get_user_by_email(email): response = HttpResponse("User exists", "text/html") response.status_code = 200 return response response = HttpResponse("User does not exist", "text/html") response.status_code = 404 return response
def get_user_and_registration_from_cookie(cookie,request): registration = get_most_recent(UserRegistration.objects.filter(cookie=cookie)) # user not found? if (not registration or len(UserRegistration.objects.filter(cookie=cookie)) == 0): return None matching_user = get_user_by_email(registration.email) if not matching_user: return None return (matching_user, registration)
def userexists(request): email = request.GET['email']; if get_user_by_email(email) : response = HttpResponse("User exists", "text/html"); response.status_code = 200; return response response = HttpResponse("User does not exist", "text/html"); response.status_code = 404; return response
def get_user_and_registration_from_cookie(cookie, request): registration = get_most_recent( UserRegistration.objects.filter(cookie=cookie)) # user not found? if (not registration or len(UserRegistration.objects.filter(cookie=cookie)) == 0): return None matching_user = get_user_by_email(registration.email) if not matching_user: return None return (matching_user, registration)
def changepassword_request(request): ## GET view, parameter username email = request.GET['username']; matching_user = get_user_by_email(email) if not matching_user: response = HttpResponse("Unknown user, did you register previously for List.it under a different email address?", "text/html"); response.status_code = 404 logevent(request,'changepassword_request',404,repr(request)) return response; req = makeChangePasswordRequest(email) send_mail('Confirm List.it change password request', gen_confirm_change_password_email(req) , '*****@*****.**', (matching_user.email,), fail_silently=False) response = render_to_response('jv3/changepassword_request.html', {'message': "(I just sent email to you at %s)" % matching_user.email}) logevent(request,'changepassword_request',200,repr((email,req.cookie,))) response.status_code = 200 return response
def createuser(request): ## as of 8.13, we now no longer require email confirmation -- we create users immediately ## on signup. email = request.POST['username'] passwd = request.POST['password'] if get_user_by_email(email): response = HttpResponse("User exists", "text/html") response.status_code = 405 logevent(request, 'createuser', 205, email) return response user_reg = UserRegistration() user_reg.when = current_time_decimal() user_reg.email = email user_reg.password = passwd ## this is unfortunate. ## couhes handling: couhes requires first & last name user_reg.couhes = (request.POST['couhes'] == 'true') ## assume this is boolean user_reg.first_name = request.POST.get('firstname', '') user_reg.last_name = request.POST.get('lastname', '') ## print "user couhes is %s " % repr(type(user.couhes)) user_reg.cookie = gen_cookie() user_reg.save() if require_account_confirmation: print "New user registration is %s " % repr(user_reg) send_mail('Did you register for Listit?', gen_confirm_newuser_email_body(user_reg), '*****@*****.**', (user_reg.email, ), fail_silently=False) response = HttpResponse("UserRegistration created successfully", "text/html") response.status_code = 200 logevent(request, 'createusr', 201, user_reg) return response ## else user = _make_user_from_registration(user_reg) response = HttpResponse("User created successfully", "text/html") response.status_code = 200 logevent(request, 'createusr', 201, user_reg) return response
def createuser(request): ## as of 8.13, we now no longer require email confirmation -- we create users immediately ## on signup. email = request.POST['username']; passwd = request.POST['password']; if get_user_by_email(email) : response = HttpResponse("User exists", "text/html"); response.status_code = 405; logevent(request,'createuser',205,email) return response user_reg = UserRegistration(); user_reg.when = current_time_decimal(); user_reg.email = email; user_reg.password = passwd; ## this is unfortunate. ## couhes handling: couhes requires first & last name user_reg.couhes = (request.POST['couhes'] == 'true'); ## assume this is boolean user_reg.first_name = request.POST.get('firstname',''); user_reg.last_name = request.POST.get('lastname',''); ## print "user couhes is %s " % repr(type(user.couhes)) user_reg.cookie = gen_cookie(); user_reg.save(); if require_account_confirmation: print "New user registration is %s " % repr(user_reg); send_mail('Did you register for Listit?', gen_confirm_newuser_email_body(user_reg) , '*****@*****.**', (user_reg.email,), fail_silently=False) response = HttpResponse("UserRegistration created successfully", "text/html"); response.status_code = 200; logevent(request,'createusr',201,user_reg) return response ## else user = _make_user_from_registration(user_reg) response = HttpResponse("User created successfully", "text/html"); response.status_code = 200; logevent(request,'createusr',201,user_reg) return response
def changepassword(request): ## POST view, parameters cookie and password cookie = request.POST['cookie']; password = request.POST['password']; assert cookie != None and len(password) > 0, "Cookie cannot be null" assert password != None and len(password) > 0, "Password cannot be null" matching_requests = ChangePasswordRequest.objects.filter(cookie=cookie) if len(matching_requests) == 0: response = HttpResponse("Sorry, I did not know about your request to change your password.","text/html") response.status_code = 405; logevent(request,'changepassword',405,repr(request)) return response; reqobject = matching_requests[0]; matching_user = get_user_by_email(reqobject.username) if not matching_user: response = HttpResponse("Sorry, I did not know about the user you are asking about: %s " % repr(reqobject.username),"text/html") response.status_code = 404; logevent(request,'changepassword',404,repr(request)) return response; matching_user.set_password(password) matching_user.save() reqobject.delete() response = render_to_response('jv3/confirmuser.html', {'message': "Your password hs been updated successfully, %s." % matching_user.email}) logevent(request,'changepassword',200,repr(cookie)) return response;