def post(self): """ Manage post """ email = self.get_argument('email') name = self.get_argument('name') question = self.get_argument('question') answer = self.get_argument('answer') message = self.get_argument('message') if email and name and question and answer and message and question == answer: """ Send mail""" try: model = EmailModel() # Contact email is the default if not model.shortcut_exists(getattr(private_settings, "CONTACT_EMAIL", "contact_email")): self.write("The email preferences are not set") else: # Replace all tags. email_object = model.find_by_shortcut(private_settings.CONTACT_EMAIL) email_pref = PreferenceModel().get_mail_server() content = micro_template(email_object['content'], { 'sender': name, 'email': email, 'message': message }) send_mail(email, email_pref['sender'], email_object['title'], content, host_pref=email_pref) self.write("ok") except Exception as e: self.write("error: " + str(e))
def post(self, *args, **kwargs): """ Change the information. If the usermail change, an email will be sended """ if self.get_secure_cookie('connected'): username = self.get_argument('name') email = self.get_argument("email") password = self.get_argument("password") confirm = self.get_argument('confirm') current = UserModel().find_by_id(self.get_secure_cookie('connected')) error = [] if not username: error.append({'message': 'The user name must be filled', 'field': 'username'}) elif current['username'] != username and UserModel().is_username_exists(username): error.append({'message': 'The user name you choose already exists.', 'field': 'username'}) if not email: error.append({'message': 'Email is required and must be valid', 'field': 'email'}) elif current['email'] != email and is_email(email) and UserModel().is_email_exists(email): error.append({'message': "Email exists, may be it's yours.", 'field': 'email'}) if password and confirm != password: error.append({'message': 'The password and its confirmation are different', 'field': 'confirm'}) if not error: mail_model = EmailModel() subject, body = mail_model.get_template('changing_mail_confirmation') if not (subject and body): raise AttributeError('Mail model "changing_mail_confirmation" is not created') registration_key = hashlib.md5(email.encode('utf-8') + str(time.time()).encode('utf-8')).hexdigest() # UserModel().create_temp_user(username, email, password, registration_key) keys = { 'website': private_settings.SITE_NAME, 'registration_key': registration_key } content = micro_template(body, keys) host_pref = PreferenceModel().get_mail_server() send_mail(host_pref['sender'], email, subject, content, host_pref) self.render( 'profile.html', errors=None, fields=None, error_message=None, messages=[{'level': 0, 'message': 'Your account has been successfully updated'}] ) else: errors = {} for err in error: errors[err['field']] = err['message'] self.render( 'profile.html', errors=error, fields=[err['field'] for err in error], error_messages=errors ) else: self.redirect('/')
def post(self): username = self.get_argument('username') email = self.get_argument('email') password = self.get_argument('password') confirm = self.get_argument('confirm') question = self.get_argument('question') answer = self.get_argument('answer') error = [] if question != answer: error.append({'message': "You didn't answer correctly to the question", "field": "question"}) if not username: error.append({'message': 'The user name must be filled', 'field': 'username'}) elif UserModel().is_username_exists(username): error.append({'message': 'The user name you choose already exists.', 'field': 'username'}) if not email: error.append({'message': 'Email is required and must be valid', 'field': 'email'}) elif UserModel().is_email_exists(email): error.append({'message': "Email exists, may be it's yours.", 'field': 'email'}) if not password: error.append({'message': 'A password is required', 'field': 'password'}) elif confirm != password: error.append({'message': 'The password and its confirmation are different', 'field': 'confirm'}) if not error: mail_model = EmailModel() subject, body = mail_model.get_template('registration') registration_key = hashlib.md5(email.encode('utf-8') + str(time.time()).encode('utf-8')).hexdigest() UserModel().create_temp_user(username, email, password, registration_key) keys = { 'website': private_settings.SITE_NAME, 'registration_key': registration_key } content = micro_template(body, keys) host_pref = PreferenceModel().get_mail_server() # FIXME: Should be async send_mail(host_pref['sender'], email, subject, content, host_pref) self.render( 'register_success.html', page='register_success', email_receiver=email ) else: messages = {} for err in error: messages[err['field']] = err['message'] self.render( 'register.html', page='register', errors=error, username=username, email=email, fields=[err['field'] for err in error], error_messages=messages )