def post(self, request): form = forms.ForgotForm(request.POST) if form.is_valid(): user = self.get_object(form.cleaned_data['email']) user = user[0] token = get_random_string(length=16) r = utils.update_user(user.db_name, user.email, token=make_password(token)) if r == 200: mail.sendUserForgotMail(user.email, token) return render( request, self.template_name, { 'form': forms.ForgotForm(), 'success': '1', 'msg': 'Please check your email for further instructions' }) else: return render( request, self.template_name, { 'form': forms.ForgotForm(), 'error': '1', 'msg': 'Network Error. Please try again later.' }) else: return render( request, self.template_name, { 'form': forms.ForgotForm(), 'error': '1', 'msg': 'Email is not registered' })
def post(self, request): form = forms.PasswordResetForm(request.POST) if form.is_valid(): user = self.get_object(request.GET.get('id'))[0] token = make_password(get_random_string(length = 16)) password = make_password(form.cleaned_data['password']) r = utils.update_user(user.db_name, user.email, token = token, password = password) if r == 200: return render(request, 'accounts/reset_done.html') else: return render(request, self.template_name, {'form': form, 'error': '1', 'msg': 'Network Error. Please try again later'}) else: return render(request, self.template_name, {'form': form, 'form_err': '1'})
def clean_privilage(self): privilage = self.cleaned_data['privilage'] email = self.cleaned_data['email'] user = self.get_object(email) if user.count() > 0: user = user[0] r = utils.update_user(user.db_name, user.email, type=privilage) if r == 200: return privilage else: raise forms.ValidationError('Network Error') else: raise forms.ValidationError('User not found')