示例#1
0
    def post(self, request, *args, **kwargs):
        result_dict = {
            "msg": "短信找回密码失败",
            "err": 1,
        }
        try:
            param_dict = json.loads(request.body)
            email_hash = param_dict.get("hash")
            new_password = param_dict.get("password")
            pycrypt_obj = PyCrypt(CryptKey)
            email = pycrypt_obj.decrypt(email_hash)
            filter_dict = {
                "identifier": email,
                "identity_type": "email",
            }
            customuserauths_objs = CustomUserAuths.objects.filter(
                **filter_dict)
            if customuserauths_objs.exists():
                pycrypt_obj = PyCrypt(CryptKey)
                crypt_password = pycrypt_obj.encrypt(new_password)
                update_filter = {
                    "custom_user_id":
                    customuserauths_objs.first().custom_user_id,
                    "identity_type__in": ["phone", "email"],
                }
                update_result = CustomUserAuths.objects.filter(
                    **update_filter).update(credential=crypt_password)
                if update_result:
                    result_dict["err"] = 0
                    result_dict["msg"] = "密码重置成功"
            else:
                result_dict["msg"] = "用户账户不存在"

        except:
            traceback.print_exc()
            logging.getLogger().error(traceback.format_exc())
            result_dict["err"] = 1
            result_dict["msg"] = '邮箱找回密码异常, %s' % traceback.format_exc()
        finally:
            return HttpResponse(json.dumps(result_dict, ensure_ascii=False))
示例#2
0
 def get(self, request, *args, **kwargs):
     result_dict = {"msg": "邮箱激活失败。", "err": 1, "data": {}}
     try:
         hash_str = request.GET.get("hash")
         pycrypt_obj = PyCrypt(CryptKey)
         crypt_str = pycrypt_obj.decrypt(hash_str)
         user_info_list = crypt_str.split("|")
         if len(user_info_list) == 3:
             user_email = user_info_list[0]
             customer_user_id = user_info_list[1]
             customer_user_auth_id = user_info_list[2]
             filter_dict = {
                 "id": customer_user_auth_id,
                 "custom_user_id": customer_user_id,
                 "identity_type": "email",
                 "identifier": user_email,
             }
             customuserauths_obj = CustomUserAuths.objects.filter(
                 **filter_dict)
             if customuserauths_obj.exists():
                 update_result = customuserauths_obj.update(status=True)
                 if update_result:
                     result_dict["err"] = 0
                     result_dict["msg"] = "邮箱激活成功"
             else:
                 result_dict["err"] = 2
                 result_dict["msg"] = "待激活邮箱账户不存在"
         else:
             result_dict["err"] = 5
             result_dict["msg"] = "邮箱激活参数错误"
     except:
         traceback.print_exc()
         logging.getLogger().error(traceback.format_exc())
         result_dict["err"] = 1
         result_dict["msg"] = '通过邮箱激活账户异常, %s' % traceback.format_exc()
     finally:
         return HttpResponse(json.dumps(result_dict, ensure_ascii=False))