示例#1
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)
示例#2
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)
示例#3
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)