def changePassword(req): u = req.user.get_profile().user current_pw = req.POST.get('current_password', '') new_pw1 = req.POST.get('new_password1', '') new_pw2 = req.POST.get('new_password2', '') if u.check_password(current_pw): if new_pw1 != new_pw2: return _jsonResponse("New passwords must match!") if new_pw1 == '' or new_pw2 == '': return _jsonResponse("Passwords must not be empty!") u.set_password(new_pw1) u.save() messages.add_message(req, messages.INFO, 'Password changed successfully.') return _jsonResponse({'redirect': '/my-settings/',}) else: return _jsonResponse("Current password is incorrect.")
def feedback(req): if req.method == 'GET': p = {'excellian': req.user.get_profile(), 'is_feedback': True, 'feedback': Feedback.objects.all().order_by('-message_date')} p.update(csrf(req)) return render_to_response(TEMPLATE_PATH + "feedback.html", p, context_instance=RequestContext(req)) elif req.method == 'POST': feedback = Feedback() feedback.excellian = req.user.get_profile() feedback.message = req.POST.get('message', '').strip() feedback.slug = _slugit(Feedback, feedback.message) if feedback.message == '': return _jsonResponse('Please enter a feedback message.') feedback.save() messages.add_message(req, messages.INFO, 'Feedback received. Thanks!') return _jsonResponse({'redirect': '/feedback/'})
def signIn(req): if req.method == 'GET': if req.user.is_authenticated(): return HttpResponseRedirect('/dashboard/') p = _createParams(req) p['is_signin'] = True return render_to_response(TEMPLATE_PATH + 'signin.html', p, context_instance=RequestContext(req)) elif req.method == 'POST': username = req.POST.get('email', '') password = req.POST.get('password', '') user = authenticate(username=username, password=password) if user is None: return _jsonResponse('Invalid sign in.') elif user.is_active: login(req, user) return _jsonResponse({'redirect': '/dashboard/'}) else: return _jsonResponse("Unable to log in.")