Esempio n. 1
0
	def post(self, tv = {}):
		tv = {}

		# validate the fields

		form = ForgotPasswordForm(self)

		if not form.validate():
			self.get({"errors": form.errors})
			return
		# validate the post value

		user_info = self.user_model.get_user_by_email_and_username(form.email.data, form.username.data)

		if(not user_info):
			tv["errors"] = {}
			tv["errors"]["invalid_email_or_username"] = [u"所填用户名和邮箱有误"]
			self.get(tv)
			return

		# continue while validate succeed
		# update password
		new_password = uuid.uuid1().hex
		new_secure_password = hashlib.sha1(new_password).hexdigest()
		update_result = self.user_model.set_user_password_by_uid(user_info["uid"], new_secure_password)

		# send password reset link to user

		mail_title = u"D2Ark社区(D2Ark.com)找回密码"
		tv = {"email": form.email.data, "new_password": new_password};
		tv["success_message"] = [u"新密码已发送至您的注册邮箱"]
		mail_content = self.render_string("user/forgot_password_mail.html", **tv)
		send(mail_title, mail_content, form.email.data)

		self.get(tv)
Esempio n. 2
0
    def post(self, template_variables={}):
        # validate the fields
        form = ForgotPasswordForm(self)

        if not form.validate():
            self.write(
                lib.jsonp.print_JSON({
                    'success': 0,
                    'message': form.errors,
                }))

        # validate the post value
        user_info = yield self.application.user_model.get_user_by_email(
            form.email_reset_pwd.data)

        if (not user_info):
            self.write(
                lib.jsonp.print_JSON({
                    'success':
                    0,
                    'message': ['Email address is not correct'],
                }))

        # continue while validate succeed
        # update password

        new_password = uuid.uuid1().hex
        new_secure_password = hashlib.sha1(new_password).hexdigest()
        update_result = yield self.application.user_model.set_user_password_by_uid(
            user_info['_id'], new_secure_password)

        # send password reset link to user
        mail_title = 'Find password'
        template_variables = {
            'email': form.email_reset_pwd.data,
            'new_password': new_password
        }
        #template_variables['success_message'] = ['New password has been sent to your email']
        #mail_content = self.render_string('user/forgot_password_mail.html', **template_variables)
        mail_content = 'New password' + new_password
        send(mail_title, mail_content, form.email_reset_pwd.data)

        self.write(
            lib.jsonp.print_JSON({
                'success':
                1,
                'message': ['New password has been sent to your email'],
            }))
Esempio n. 3
0
File: user.py Progetto: Runsher/89s
    def post(self, template_variables={}):
        template_variables = {}

        # validate the fields

        form = ForgotPasswordForm(self)

        if not form.validate():
            self.get({"errors": form.errors})
            return

        # validate the post value

        user_info = self.user_model.get_user_by_email_and_username(
            form.email.data, form.username.data)

        if (not user_info):
            template_variables["errors"] = {}
            template_variables["errors"]["invalid_email_or_username"] = [
                u"所填用户名和邮箱有误"
            ]
            self.get(template_variables)
            return

        # continue while validate succeed
        # update password

        new_password = uuid.uuid1().hex
        new_secure_password = hashlib.sha1(new_password).hexdigest()
        update_result = self.user_model.set_user_password_by_uid(
            user_info["uid"], new_secure_password)

        # send password reset link to user

        mail_title = u"前端社区(F2E.im)找回密码"
        template_variables = {
            "email": form.email.data,
            "new_password": new_password
        }
        template_variables["success_message"] = [u"新密码已发送至您的注册邮箱"]
        mail_content = self.render_string("user/forgot_password_mail.html",
                                          **template_variables)
        send(mail_title, mail_content, form.email.data)

        self.get(template_variables)
Esempio n. 4
0
 def send_mail(self, email, user_id):
     if self.settings['debug']:
         self.muser.do_activate_account(user_id)
         return
     title = u'欢迎加入梧桐'
     content = u'{proto}://{host}/{path}'.format(
         proto=self.request.protocol,
         host=self.request.host,
         path='account?activate_account&v=&next=/' + util.encrypt(user_id)
     )
     if not sendmail.send(title, content, email):
         errmsg = "send email to '%s' error" % email
         gen_log.error(errmsg)
         raise Exception(errmsg)
Esempio n. 5
0
    def post(self, template_variables = {}):
        template_variables = {}

        # validate the fields

        form = RegisterForm(self)

        if not form.validate():
            self.get({"errors": form.errors})
            return

        # validate duplicated

        duplicated_email = self.user_model.get_user_by_email(form.email.data)
        duplicated_username = self.user_model.get_user_by_username(form.username.data)

        if(duplicated_email or duplicated_username):
            template_variables["errors"] = {}

            if(duplicated_email):
                template_variables["errors"]["duplicated_email"] = [u"所填邮箱已经被注册过"]

            if(duplicated_username):
                template_variables["errors"]["duplicated_username"] = [u"所填用户名已经被注册过"]

            self.get(template_variables)
            return

        # validate reserved

        if(form.username.data in self.settings.get("reserved")):
            template_variables["errors"] = {}
            template_variables["errors"]["reserved_username"] = [u"用户名被保留不可用"]
            self.get(template_variables)
            return

        # continue while validate succeed

        secure_password = hashlib.sha1(form.password.data).hexdigest()

        user_info = {
            "email": form.email.data,
            "password": secure_password,
            "username": form.username.data,
            "created": time.strftime('%Y-%m-%d %H:%M:%S')
        }

        if(self.current_user):
            return
        
        user_id = self.user_model.add_new_user(user_info)
        
        if(user_id):
            do_login(self, user_id)

            # send register success mail to user

            mail_title = u"tuila.me 注册成功通知"
            mail_content = self.render_string("user/register_mail.html")
            send(mail_title, mail_content, form.email.data)

        self.redirect(self.get_argument("next", "/"))
Esempio n. 6
0
    def post(self, template_variables = {}):
        template_variables = {}

        # validate the fields

        form = RegisterForm(self)

        if not form.validate():
            self.get({"errors": form.errors})
            return

        # validate duplicated

        duplicated_email = self.user_model.get_user_by_email(form.email.data)
        duplicated_username = self.user_model.get_user_by_username(form.username.data)

        if(duplicated_email or duplicated_username):
            template_variables["errors"] = {}

            if(duplicated_email):
                template_variables["errors"]["duplicated_email"] = [u"所填邮箱已经被注册过"]

            if(duplicated_username):
                template_variables["errors"]["duplicated_username"] = [u"所填用户名已经被注册过"]

            self.get(template_variables)
            return

        # validate reserved

        if(form.username.data in self.settings.get("reserved")):
            template_variables["errors"] = {}
            template_variables["errors"]["reserved_username"] = [u"用户名被保留不可用"]
            self.get(template_variables)
            return

        # continue while validate succeed

        secure_password = hashlib.sha1(form.password.data).hexdigest()

        user_info = {
            "email": form.email.data,
            "password": secure_password,
            "username": form.username.data,
            "intro": "",
            "plus": 0,
            "followers": 0,
            "posts": 0,
            "created": time.strftime('%Y-%m-%d %H:%M:%S')
        }

        if(self.current_user):
            return
        
        user_id = self.user_model.add_new_user(user_info)
        
        if(user_id):
            do_login(self, user_id)

            # send register success mail to user

            mail_title = u"tuila.me 注册成功通知"
            mail_content = self.render_string("user/register_mail.html")
            send(mail_title, mail_content, form.email.data)

        self.redirect(self.get_argument("next", "/"))
Esempio n. 7
0
    def post(self, template_variables = {}):
        template_variables = {}

        # validate the fields

        form = RegisterForm(self)

        if not form.validate():
            self.get({"errors": form.errors})
            return

        # validate duplicated

        duplicated_email = self.user_model.get_user_by_email(form.email.data)
        duplicated_username = self.user_model.get_user_by_username(form.username.data)
        #duplicated_collegename = self.college_model.get_college_by_college_name(form.collegename.data)

        if(duplicated_email or duplicated_username):
            template_variables["errors"] = {}

            if(duplicated_email):
                template_variables["errors"]["duplicated_email"] = [u"所填邮箱已经被注册过"]

            if(duplicated_username):
                template_variables["errors"]["duplicated_username"] = [u"所填用户名已经被注册过"]

            self.get(template_variables)
            return

        # validate reserved

        if(form.username.data in self.settings.get("reserved")):
            template_variables["errors"] = {}
            template_variables["errors"]["reserved_username"] = [u"用户名被保留不可用"]
            self.get(template_variables)
            return

        # validate college name
        #if duplicated_collegename is None:
         #   template_variables["errors"] = {}
          #  template_variables["errors"]["duplicated_collegename"] = [u"学校名称不正确(进入所有学校页面 3n1b.com/colleges 核对你想输入的学校名称)"]
           # self.get(template_variables)
           # return

        # continue while validate succeed

        secure_password = hashlib.sha1(form.password.data).hexdigest()

        user_info = {
            "email": form.email.data,
            "password": secure_password,
            "username": form.username.data,
            "collegename": "请设置您的学校",
            "created": time.strftime('%Y-%m-%d %H:%M:%S')
        }

        if(self.current_user):
            return
        
        user_id = self.user_model.add_new_user(user_info)
        
        if(user_id):
            do_login(self, user_id)

            # send register success mail to user

            mail_title = u"叁年壹班 注册成功通知"
            mail_content = self.render_string("user/register_mail.html")
            send(mail_title, mail_content, form.email.data)

        self.redirect(self.get_argument("next", "/register/college"))
Esempio n. 8
0
    def post(self, template_variables={}):
        template_variables = {}

        # validate the fields

        form = RegisterForm(self)

        if not form.validate():
            self.get({"errors": form.errors})
            return

        # validate duplicated

        duplicated_email = self.user_model.get_user_by_email(form.email.data)
        duplicated_username = self.user_model.get_user_by_username(form.username.data)
        # duplicated_collegename = self.college_model.get_college_by_college_name(form.collegename.data)

        if duplicated_email or duplicated_username:
            template_variables["errors"] = {}

            if duplicated_email:
                template_variables["errors"]["duplicated_email"] = [u"所填邮箱已经被注册过"]

            if duplicated_username:
                template_variables["errors"]["duplicated_username"] = [u"所填用户名已经被注册过"]

            self.get(template_variables)
            return

        # validate reserved

        if form.username.data in self.settings.get("reserved"):
            template_variables["errors"] = {}
            template_variables["errors"]["reserved_username"] = [u"用户名被保留不可用"]
            self.get(template_variables)
            return

        # validate college name
        # if duplicated_collegename is None:
        #   template_variables["errors"] = {}
        #  template_variables["errors"]["duplicated_collegename"] = [u"学校名称不正确(进入所有学校页面 3n1b.com/colleges 核对你想输入的学校名称)"]
        # self.get(template_variables)
        # return

        # continue while validate succeed

        secure_password = hashlib.sha1(form.password.data).hexdigest()

        user_info = {
            "email": form.email.data,
            "password": secure_password,
            "username": form.username.data,
            "collegename": "请设置您的学校",
            "created": time.strftime("%Y-%m-%d %H:%M:%S"),
        }

        if self.current_user:
            return

        user_id = self.user_model.add_new_user(user_info)

        if user_id:
            do_login(self, user_id)

            # send register success mail to user

            mail_title = u"叁年壹班 注册成功通知"
            mail_content = self.render_string("user/register_mail.html")
            send(mail_title, mail_content, form.email.data)

        self.redirect(self.get_argument("next", "/register/college"))
Esempio n. 9
0
    def post(self, template_variables={}):
        # validate the fields

        form = RegisterForm(self)

        if not form.validate():
            self.get({'errors': form.errors})
            return

        # validate duplicated
        duplicated_email = yield self.application.user_model.get_user_by_email(
            form.email.data)
        duplicated_username = yield self.application.user_model.get_user_by_username(
            form.username.data)

        if (duplicated_email or duplicated_username):
            template_variables['errors'] = {}

            if (duplicated_email):
                template_variables['errors']['duplicated_email'] = [
                    'Email address has been registered'
                ]

            if (duplicated_username):
                template_variables['errors']['duplicated_username'] = [
                    'Username has been registered'
                ]

            self.get(template_variables)
            return

        # validate reserved
        if (form.username.data in self.settings.get('reserved')):
            template_variables['errors'] = {}
            template_variables['errors']['reserved_username'] = [
                'This username is reserved'
            ]
            self.get(template_variables)
            return

        # continue while validate succeed
        secure_password = hashlib.sha1(form.password.data).hexdigest()

        user_info = {
            'email': form.email.data,
            'password': secure_password,
            'username': form.username.data,
            'created': time.strftime('%Y-%m-%d %H:%M:%S')
        }

        user_id = yield self.application.user_model.add_new_user(user_info)

        if (user_id):
            yield do_login(self, user_id)

            # send register success mail to user

            mail_title = 'Register successfully'
            mail_content = self.render_string('user/register_mail.html')
            send(mail_title, mail_content, form.email.data)

        self.redirect(self.get_argument('next', '/'))