示例#1
0
        public async Task <bool> ForgetPassword(MS_USER entity)
        {
            string html    = string.Empty;
            var    builder = new StringBuilder();
            var    pinCode = string.Empty;
            var    rnd     = new Random();
            bool   resp    = false;

            if (entity == null || string.IsNullOrEmpty(entity.IMail))
            {
                return(false);
            }

            try
            {
                for (int i = 0; i < 3; i++)
                {
                    pinCode += string.Format("{0:00_}", rnd.Next(00, 99));
                }


                entity.IResetPin = pinCode.Replace("_", "");

                var rowUpdate = await Update(entity);

                if (rowUpdate > 0)
                {
                    var Request = new Microsoft.AspNetCore.Http.HttpContextAccessor().HttpContext.Request;

                    string param = Project.EncodeBase64(entity.IUserId);
                    var    enc   = Project.Encrypt(entity.IUserId);

                    string fullUrl = string.Format("{0}://{1}{2}{3}",
                                                   Request.Scheme, Request.Host.Value, Request.PathBase, $"/Account/ForgetPassword&param={param}?verify={enc}");

                    builder.AppendLine($"Here are the details outlining your new password. <br/>");
                    builder.AppendLine($"USER ID :  	{ entity.IUserId } <br/>");
                    builder.AppendLine($"PIN CODE :  	{ pinCode.Replace("_", " ") } <br/>");
                    builder.AppendLine($"Here are the details outlining your new password. <br/>");
                    builder.AppendLine($" <a href='{ fullUrl }' ></a>");

                    resp = await EmailService.SendForResetPassword(new List <string> {
                        entity.IMail
                    },
                                                                   "Your Password has been reset",
                                                                   builder.ToString());

                    string respText = (resp) ? "Successfully" : "Failured";

                    Logger.LogInformation($"Send email [{respText}] to [{entity.IMail}] pin code is [{pinCode}] ");
                }
                else
                {
                    Logger.LogInformation($"Can not update pin code [{pinCode}] for user [{entity.IUserId}]");
                }
            } catch (Exception ex) {
                Logger.LogError(ex.Message);
            }


            return(resp);
        }
示例#2
0
 public static void Configure(Microsoft.AspNetCore.Http.HttpContextAccessor accessor)
 {
     s_accessor = accessor;
 }