예제 #1
0
    def get(self, request, *args, **kwargs):
        if not "base64string" in kwargs:
            kwargs['getError'] = True
            return super(ForgetReset, self).get(request, *args, **kwargs)
        
        aes = AESCipher()
        data=None
        try:
            data = aes.decrypt(kwargs['base64string']).split("~|@|~")
        except Exception as e:
            print(e)
            kwargs['getError'] = True
            return super(ForgetReset, self).get(request, *args, **kwargs)
        
        timeout = time.mktime(time.strptime(data[4], '%Y-%m-%d-%H-%M-%S'))
        now = time.mktime(timezone.now().timetuple())
        
        if  now>timeout:
            kwargs['timeout'] = "重置資料已超時,請重新按 忘記密碼。"
            return super(ForgetReset, self).get(request, *args, **kwargs)
        
        try:
            user = User.objects.get(id=data[0])
            if (user.username!=data[1] and user.email!=data[2] and user.profile.resetCode!=data[3]):
                kwargs['getError'] = True
            kwargs['form'] = ResetPwd()
        except Exception as e:
            print(e)

        
        return super(ForgetReset, self).get(request, *args, **kwargs)
예제 #2
0
    def get(self, request, *args, **kwargs):
        if not "base64string" in kwargs:
            kwargs["getError"] = True
            return super(ForgetReset, self).get(request, *args, **kwargs)

        aes = AESCipher()
        data = None
        try:
            data = aes.decrypt(kwargs["base64string"]).split("~|@|~")
        except Exception as e:
            print(e)
            kwargs["getError"] = True
            return super(ForgetReset, self).get(request, *args, **kwargs)

        timeout = time.mktime(time.strptime(data[4], "%Y-%m-%d-%H-%M-%S"))
        now = time.mktime(timezone.now().timetuple())

        if now > timeout:
            kwargs["timeout"] = "重置資料已超時,請重新按 忘記密碼。"
            return super(ForgetReset, self).get(request, *args, **kwargs)

        try:
            user = User.objects.get(id=data[0])
            if user.username != data[1] and user.email != data[2] and user.profile.resetCode != data[3]:
                kwargs["getError"] = True
            kwargs["form"] = ResetPwd()
        except Exception as e:
            print(e)

        return super(ForgetReset, self).get(request, *args, **kwargs)
예제 #3
0
    def sendMail(self, request, user, resetCode):

        timeout = datetime.datetime.strftime(timezone.now() + datetime.timedelta(hours=24), "%Y-%m-%d-%H-%M-%S")
        cipher = AESCipher()
        code = cipher.encrypt(
            str(user.id) + "~|@|~" + user.username + "~|@|~" + user.email + "~|@|~" + resetCode + "~|@|~" + timeout
        )

        url = "http://" + self.getHost(request) + reverse("account:forgetReset", args=(code,))
        email = user.email
        html = """
            <!DOCTYPE html>
            <html>
            <body>
            <span>這是您的重置碼(分大小寫):</span><span style="background-color:#eee">{code}</span><br>
            以下是重置您密碼的網址:<br>
            <a href="{url}" target="_blank">點此重置您密碼</a>
            </body>
            </html>
        """.format(
            url=url, name=user.username, code=resetCode
        )
        text = "這是您的重置碼(分大小寫):\n {code} \n 以下是重置您密碼的網址:\n{url}".format(url=url, code=resetCode)
        smtp = SMTP()

        return smtp.send(email, "密碼重置", html, text)  # 收件人, 標題, 內容
예제 #4
0
 def checkUser(self,request, *args, **kwargs):
     base64 = kwargs['base64string']
     aes = AESCipher()
     data = aes.decrypt(base64).split("~|@|~")
     user = User.objects.get(id=data[0])
     if user.username!=data[1]:
         return False
     if user.email!=data[2]:
         return False
     user.profile.isVerified = True
     user.profile.save()
     logout(request)
     return True
예제 #5
0
 def checkUser(self, request, *args, **kwargs):
     base64 = kwargs["base64string"]
     aes = AESCipher()
     data = aes.decrypt(base64).split("~|@|~")
     user = User.objects.get(id=data[0])
     if user.username != data[1]:
         return False
     if user.email != data[2]:
         return False
     user.profile.isVerified = True
     user.profile.save()
     logout(request)
     return True
예제 #6
0
 def post(self, request, *args, **kwargs):
     cipher = AESCipher()
     code = cipher.encrypt(str(request.user.id)+"~|@|~"+request.user.username+"~|@|~"+request.user.email)
     url = "http://"+self.getHost(request)+reverse('account:verifyEmail', args=(code,))
     email = request.user.email
     html="""
         <!DOCTYPE html>
         <html>
         <body>
         <h3>會員 {name}:</h3>
         <p>謝謝您的註冊。</p>
         
         以下是您的驗證網址:
         <a href="{url}">點此驗證</a>
         </body>
         </html>
     """.format(url=url, name=request.user.username)
     text = "以下是你的驗證網址:\n {url}".format(url=url)
     response = {}
     smtp = SMTP()
     response['success'] = smtp.send(email, "Email 驗證", html , text) # 收件人, 標題, 內容
     return JsonResponse(response)
예제 #7
0
 def sendMail(self,request, user, resetCode):
     
     timeout = datetime.datetime.strftime(timezone.now()+ datetime.timedelta(hours=24), '%Y-%m-%d-%H-%M-%S')
     cipher = AESCipher()
     code = cipher.encrypt(str(user.id)+"~|@|~"+user.username+"~|@|~"+user.email+"~|@|~"+resetCode+
                           "~|@|~"+timeout )
     
     url = "http://"+self.getHost(request)+reverse('account:forgetReset', args=(code,))
     email = user.email
     html="""
         <!DOCTYPE html>
         <html>
         <body>
         <span>這是您的重置碼(分大小寫):</span><span style="background-color:#eee">{code}</span><br>
         以下是重置您密碼的網址:<br>
         <a href="{url}" target="_blank">點此重置您密碼</a>
         </body>
         </html>
     """.format(url=url, name=user.username, code = resetCode)
     text = "這是您的重置碼(分大小寫):\n {code} \n 以下是重置您密碼的網址:\n{url}".format(url=url, code = resetCode)
     smtp = SMTP()
     
     return smtp.send(email, "密碼重置", html , text) # 收件人, 標題, 內容
예제 #8
0
 def post(self, request, *args, **kwargs):
     cipher = AESCipher()
     code = cipher.encrypt(str(request.user.id) + "~|@|~" + request.user.username + "~|@|~" + request.user.email)
     url = "http://" + self.getHost(request) + reverse("account:verifyEmail", args=(code,))
     email = request.user.email
     html = """
         <!DOCTYPE html>
         <html>
         <body>
         <h3>會員 {name}:</h3>
         <p>謝謝您的註冊。</p>
         
         以下是您的驗證網址:
         <a href="{url}">點此驗證</a>
         </body>
         </html>
     """.format(
         url=url, name=request.user.username
     )
     text = "以下是你的驗證網址:\n {url}".format(url=url)
     response = {}
     smtp = SMTP()
     response["success"] = smtp.send(email, "Email 驗證", html, text)  # 收件人, 標題, 內容
     return JsonResponse(response)