Пример #1
0
    def post(self):
        username = self.get_argument("username", None)
        password = self.get_argument("password", None)
        if username and password:
            password = getSha1(password)
            member = Member.getMemberByUsernameAndPassword(username, password)
            if member:                
                self.session["logined"] = True
                self.session["mid"] = member.mid
                self.session.save()
                cookie_string = self.dumpsJson(logined=True, mid=member.mid)
                self.set_secure_cookie(self.cookie_name, cookie_string)
                self.redirect("/")
            else:
                self.finish(json.dumps({"status":"error", "info":"member not found"}))

        else:
            self.finish(json.dumps({"status":"error", "info":"arguments not matched"}))
Пример #2
0
 def post(self):
     data = json.loads(self.request.body)
     email = str(data.get("email", ""))
     code = str(data.get("code",""))
     rands_str = self.session.get("regist_verify")
     if matched("email", email) and matched("verify", code):
         if code == rands_str:
             is_existed = Member.getMemberByEmail(email)
             if is_existed:
                 self.finishedMsg(status="error", info="email already existed")
             else:
                 regist_id = getSha1(str(uuid.uuid4()))
                 regist_dict = {"email":email, "timestamp": time.time()}
                 self.mc.set(regist_id, regist_dict, time=1200)
                 regist_url = "%s/accounts/regist_with_code?code=%s" %(self.prefix_url, regist_id)
                 body = {
                     "from": "Administrator <*****@*****.**>",
                     "to": email,
                     "subject": "REGISTRATION",
                     "text": regist_url
                 }                    
                 mail_request = HTTPRequest(
                     url=mailgun_url, 
                     method="POST",
                     auth_username=mailgun_username,
                     auth_password=mailgun_password,
                     body=urlencode(body))
                 http_client = AsyncHTTPClient()
                 http_client.fetch(mail_request, callback=(yield gen.Callback("resp")))
                 response = yield gen.Wait("resp")
                 logging.info(response.body)
                 self.session["regist_verify"] = None
                 self.session.save()
                 if response.code == 200:
                     self.finishedMsg(status="success", info="mail had queued")
                 else:
                     self.finishedMsg(status="error", info="send mail fails")
         else:
             self.finishedMsg(status="error", info="verify not matched")
     else:
         self.finishedMsg(status="error", info="email or verify code not valid")
Пример #3
0
    def post(self):
        data = self.request.body
        form_data = json.loads(data)
        regist_id = form_data["regist_id"]
        regist_dict = self.mc.get(str(regist_id))

        if regist_dict:
            email       = regist_dict["email"]
            username    = form_data["username"]
            password    = form_data["password"]
            repeat      = form_data["repeat"]

            if password==repeat:
                is_existed = Member.getMemberByEmailAndUsername(email, username)
                if is_existed:
                    self.finishedMsg(status="error", info="email or username existed")
                else:                    
                    if (time.time() - regist_dict["timestamp"]) < 300:
                        is_saved = Member.create(
                            email       = email,
                            username    = username,
                            password    = getSha1(password),
                            created     = datetime.now(),
                            modified    = datetime.now(),
                            is_enabled  = True
                        )
                        if is_saved:
                            del self.mc[regist_id]                       
                            self.finishedMsg(status="success", info="regist success")
                        else:
                            self.finishedMsg(status="error", info="error when save record")
                    else:
                        self.finishedMsg(status="error", info="regist code expired")
            else:
                self.finishedMsg(status="error", info="password not matched")
        else:
            self.finishedMsg(status="error", info="regist_id not found")