def __init__(self, *args, **kwargs): if kwargs.has_key('request'): self.request = kwargs['request'] del kwargs['request'] super (SignUpForm, self).__init__(*args,**kwargs) #add recaptcha Utils.add_recaptcha_to_form(self.request, self)
def _process(self, request): user = self.request.user password = self.cleaned_data.get('new_password', '') user.set_password(password) user.save() Utils.set_msg(self.request, "You password has been updated. Please login now. ") return {'return': 302, 'redirect_url': reverse('login')}
def __init__(self, *args, **kwargs): if kwargs.has_key('request'): self.request = kwargs['request'] del kwargs['request'] super(CommentForm, self).__init__(*args, **kwargs) #add recaptcha if not Utils.is_login(self.request): self = Utils.add_recaptcha_to_form(self.request, self)
def _render_string(self, request, node_dict={}): """ Sub render method for inline-html :param request - Django request object :param node_dict - dict to be passed to template :return: dict """ return Utils.render_to_string(node_dict['x_template'], node_dict, context_instance=RequestContext(request))
def clean_passcode(self): """ check the passcode """ passcode = self.cleaned_data.get('passcode', '') site = Utils.get_site(self.request) if site and site.get('site_code'): if site.get('site_code') != passcode: raise forms.ValidationError("Invalid Password.") return passcode
def _render_string(self, request, node_dict={}): node_dict['node'] = self node_dict['form'] = self._create(request=request) node_dict = self.templates_to_node_dict(request, node_dict) template_html = NodeTemplate.fallback_template(request, self.x_template_html) return Utils.render_to_string(template_html, node_dict, context_instance=RequestContext(request))
def _render_http(self, request, node_dict, flag_html=False): """ Sub render method for normal HTTP :param request - Django request object :param node_dict - dict to be passed to template :return: dict """ code = int(node_dict.get('return')) msg = node_dict.get('msg') redirect_url = node_dict.get('redirect_url') # check for error in implementation if int(code) == 302 and not redirect_url: raise Exception("Redirect URL is not found. ") # pragma: no cover elif int(code) >= 400 and not msg: raise Exception("No error detail. ") # pragma: no cover # msg if msg: Utils.set_msg(request, msg) # redirect if redirect_url: try: print "---> going to do a redict: %s" % redirect_url return redirect(redirect_url) except NoReverseMatch: return redirect("/") # error if code >= 400: return render_to_response(node_dict['x_error_template'], node_dict, context_instance=RequestContext(request)) # render if flag_html: t = loader.get_template(node_dict['x_template']) c = Context(node_dict) html = t.render(c) return html return render_to_response(node_dict['x_template'], node_dict, context_instance=RequestContext(request))
def _process(self, request): # Create user account raw_email = self.cleaned_data.get("email", None) display_name = self.cleaned_data.get("display_name", None) password = self.cleaned_data.get("password", None) user_email = SignUpForm.normalize_email(self.request, raw_email) new_user = User.objects.create_user(user_email, user_email, password=password) new_user.is_active = True new_user.actual_email = raw_email new_user.display_name = display_name new_user.display_name_slug = slugify(display_name) new_user.save() user = authenticate(username=user_email, password=password) if user is not None: auth_login(self.request, user) Utils.set_msg(self.request, "Thank you, your account has been created. ") return {'return':'302', 'redirect_url': reverse('login')}
def _process(self, request): # create the token raw_email = self.cleaned_data.get('email', '') t = Token( domain=Utils.get_domain(request), email=raw_email, token=Token.generate_token(), type='reset_password', used=False, expired=datetime.datetime.now() + datetime.timedelta(days=3), ) t.save() # create the email site = Utils.get_site(self.request) if site and site.get('email_manager'): from_email = site.get('email_manager') else: raise Exception("No account email set.") # pragma: no cover domain = Utils.get_domain(request) link = reverse('reset-password', kwargs={'code': t.token}) subject = "Reset your password" msg_plain = "Click there link to reset your password: <a href=\"%s\">%s</a>" % ( link, link) t.url = link t.save() # send email try: EmailUtils.send_email(from_email, raw_email, subject, msg_plain) except Exception, e: # pragma: no cover return { 'return': 302, # pragma: no cover 'msg': 'Oop, we are having diffculty to send you email', 'redirect_url': reverse('login') }
def wrap_inner(*args, **kwargs): request = args[1] site = Utils.get_site(request) if (kwargs.get('ssl') and site['site_has_ssl']) and (not request.is_secure()): url = request.build_absolute_uri(request.get_full_path()) url_split = urlsplit(url) scheme = 'https' if url_split.scheme == 'http' else url_split.scheme ssl_port = 443 url_secure_split = ( scheme, "%s:%d" % (url_split.hostname or '', ssl_port)) + url_split[2:] secure_url = urlunsplit(url_secure_split) return HttpResponseRedirect(secure_url) else: return func(*args, **kwargs)
def fallback_template(request, filename): site = Utils.get_site(request) if filename: try: path = site['site_folder'] + "/themes/" + site[ 'site_theme'] + "/" + filename loader.get_template(path) return path except (TemplateDoesNotExist, AttributeError), e: pass try: path = "dj_node/" + "themes/" + site[ 'dj_theme'] + "/" + filename loader.get_template(path) return path except (TemplateDoesNotExist, AttributeError), e: pass
def process_request(self, request): if not request.is_secure(): # get secure url site = Utils.get_site(request) url = request.build_absolute_uri(request.get_full_path()) url_split = urlsplit(url) scheme = 'https' if url_split.scheme == 'http' else url_split.scheme ssl_port = 443 url_secure_split = (scheme, "%s:%d" % (url_split.hostname or '', ssl_port)) + url_split[2:] secure_url = urlunsplit(url_secure_split) # enforce url for site if (site['site_https'] and site['site_has_ssl']): return HttpResponseRedirect(secure_url) # enforce https for /admin if (request.get_full_path().lower().startswith('/admin') and site['site_has_ssl']): return HttpResponseRedirect(secure_url)
def wrap_inner(*args, **kargs): # get the argument frrom the func (method route(cls, request) kclass = args[0] request = args[1] # count number of permisson passed passed_count = 0 flag_pass = False flag_login_required = False for perm in kclass.x_perm: if perm == 'login': flag_login_required = True if Utils.has_perm(request, perm): passed_count = passed_count + 1 # determine pass or not if len(kclass.x_perm) == passed_count: flag_pass = True # handle failed permission if flag_pass == False: if flag_login_required: result = { 'return': '302', 'msg': 'Please login to continue', 'redirect_url': '/login/' } return kclass()._render(request, result) else: result = { 'return': '302', 'msg': 'Sorry, you do not have permission to continue', 'redirect_url': '/' } return kclass()._render(request, result) # handle passed permission return func(*args, **kargs)
def __init__(self, *args, **kwargs): if kwargs.has_key('request'): self.request = kwargs['request'] del kwargs['request'] super(ForgotPasswordForm, self).__init__(*args, **kwargs) Utils.add_recaptcha_to_form(self.request, self)
def normalize_email(request, email): norm_email = None mojo_domain = Utils.get_domain(request) if email: norm_email = mojo_domain + "-" + email return norm_email