예제 #1
0
    def index(self, name=None, email=None, password1=None, password2=None):
        if not name:
            return template.render("register.html")
        # Server side validation
        if not userinfo.validateUsername(name):
            return "Invalid username"
        if not email:
            return "Email is missing"
        if not password1:
            return "Password is missing"
        if not userinfo.validateEmail(email):
            return "Invalid email"

        if User.query.filter_by(username=name).first():
            return template.render("register.html" \
          , user_already_exists=True, submit=True)

        if User.query.filter_by(email=email).first():
            return serve_template("register.html" \
         , user_email_exists=True, submit=True)
        authkey = userinfo.generate_auth_key()
        password = userinfo.md5pass(password1)
        # Clean the password fields - security
        password1 = None
        password2 = None
        # Insert the new user
        new_user = User(\
         username = name, \
         email = email, \
         password = password, \
         authkey = authkey, \
         auth = 0, \
         t_register = datetime.now(), \
         t_login = datetime.now(), \
         t_seen = datetime.now() )
        sender = apt_portal.get_config("mail", "register_sender")
        template.sendmail("register.mail" \
         , sender = sender \
         , destination = email \
         , username = name \
         , authkey = authkey \
         , sitename = "localhost" \
        )
        return template.render("register.html", submit=True)
예제 #2
0
파일: register.py 프로젝트: Nitri0/tribus
    def index(self, name=None, email=None, password1=None, password2=None):
        if not name:
            return template.render("register.html")
        # Server side validation
        if not userinfo.validateUsername(name):
            return "Invalid username"		
        if not email:
            return "Email is missing"
        if not password1:
            return "Password is missing"            
        if not userinfo.validateEmail(email): 
            return "Invalid email"

        if User.query.filter_by(username = name).first():
            return template.render("register.html" \
        		, user_already_exists=True, submit=True)
        
        if User.query.filter_by(email = email).first():
            return serve_template("register.html" \
        	, user_email_exists=True, submit=True)        
        authkey = userinfo.generate_auth_key()
        password = userinfo.md5pass(password1)
        # Clean the password fields - security
        password1 = None
        password2 = None
        # Insert the new user
        new_user = User(\
        	username = name, \
        	email = email, \
        	password = password, \
        	authkey = authkey, \
        	auth = 0, \
        	t_register = datetime.now(), \
        	t_login = datetime.now(), \
        	t_seen = datetime.now() )
        sender = apt_portal.get_config("mail", "register_sender")
        template.sendmail("register.mail" \
        	, sender = sender \
        	, destination = email \
        	, username = name \
        	, authkey = authkey \
        	, sitename = "localhost" \
        )
        return template.render("register.html", submit=True)
예제 #3
0
def sendmail(template_filename, **kwargs):
    """
    Sends a mails using a mako template file
    @param template_filename: template to be used for the mail content
    @param kwargs: keyword arguments to be used on the template  
    """
    try:
        mail_server = apt_portal.get_config("mail", "smtp_server")
    except NoOptionError:
        mail_server = "localhost"

    message = render(template_filename, **kwargs)

    fromaddr = kwargs['sender']
    toaddrs = kwargs['destination']

    server = smtplib.SMTP(mail_server)
    server.sendmail(fromaddr, toaddrs, message)
    server.quit() 
예제 #4
0
def set_directories(templates_directories, module_directory):
    """ 
	Sets the following configuration directories:
		templates_directories - list of dirs to lookup for templates
		module_directory - directory to keep cached template modules		
	"""	
    global _template_lookup, _media_base_url
    try:
        _media_base_url = apt_portal.get_config("media", "base_url") 
    except (NoOptionError, NoSectionError):
        _media_base_url = ''
    
    # Template rendering with internationalization support
    _template_lookup = TemplateLookup(directories=templates_directories 
    	, module_directory=module_directory 
    	, input_encoding='utf-8' 
    	, output_encoding='utf-8' 
    	, encoding_errors='replace' 
    	, default_filters=['strip_none'] 
    	, imports=['from apt_portal.template import strip_none, html_lines, quote']
	)
예제 #5
0
 def index(self, name = None, email = None, comment = None):
     if not name:
         return template.render("contact.html")
     # server side input validation
     if not email:
         return "Email is missing"
     if not comment or len(comment)<10:
         return "Comment is missing"
     if not userinfo.validateEmail(email):            
         return "Invalid email"  
     referer = controller.get_header('Referer')
     if not referer or not referer.startswith(controller.base_url()):
         return "Not Allowed"		
     contact_recipient = apt_portal.get_config("mail", "contact_recipient")
     id = int(time.time())
     template.sendmail('contact.mail'\
 		, sender = '"%s" <%s>' % (name, email)
 		, destination = contact_recipient
 		, comment = comment
         , app_name = apt_portal.app_name
         , id = id
 	)  
     return template.render("contact.html", contact_received=1)