Ejemplo n.º 1
0
        //public static string token;
        public static LoginCheckPointModel LoginCheckPoint(string user_name, string ip_address, bool isFirst, string type)
        {
            var refId = DateTime.UtcNow.Ticks.ToString();
            var logId = SmtpProvider.Info(refId, "LoginCheckPoint", "Update on login success", "LoginCheckPoint", "LoginCheckPoint", "");
            //var Country = ClsFunction.GetLocationFromIP(ip_address);
            string ip_country = type;
            string r_token    = "";

            try
            {
                var MsgReponse = RegistrationContext.LoginCheckPoint(user_name, ip_address, ip_country);

                if (MsgReponse.Split('|')[0] == "IP")
                {
                    if (isFirst)
                    {
                        long           Datetimenow = DateTime.UtcNow.ToFileTimeUtc();
                        RegisteredUser regUser     = new RegisteredUser();
                        regUser = RegistrationContext.GetUserDetails(user_name);
                        string t = regUser.RegistereduserId.ToString() + Guid.NewGuid().ToString();
                        r_token = ClsFunction.GenerateResetToken(t + ":" + Datetimenow);
                        SendLogincheckpointMail(regUser, ip_address, r_token);
                    }
                    MsgReponse = "S|Success";
                }

                return(new LoginCheckPointModel()
                {
                    IsValid = true, ErrorCode = ErrorProvider.ErrorCode.Success.ToString(), ErrorMessage = MsgReponse, token = r_token
                });
            }
            catch (SqlException sqex)
            {
                RegisteredUser user = new RegisteredUser()
                {
                    Username        = user_name,
                    Registration_ip = ip_address
                };
                SmtpProvider.Error <RegisteredUser, string>(sqex, "", refId, "LoginCheckPoint", "Update on login success", "LoginCheckPoint", sqex.Message, user, "", "999", logId);

                return(new LoginCheckPointModel()
                {
                    IsValid = false, ErrorCode = ErrorProvider.ErrorCode.Failure.ToString(), ErrorMessage = "F|Failed", token = ""
                });
            }
            catch (Exception ex)
            {
                RegisteredUser user = new RegisteredUser()
                {
                    Username        = user_name,
                    Registration_ip = ip_address
                };
                SmtpProvider.Error <RegisteredUser, string>(ex, "", refId, "LoginCheckPoint", "Update on login success", "LoginCheckPoint", ex.Message, user, "", "999", logId);

                return(new LoginCheckPointModel()
                {
                    IsValid = false, ErrorCode = ErrorProvider.ErrorCode.Failure.ToString(), ErrorMessage = "F|Failed", token = ""
                });
            }
        }
Ejemplo n.º 2
0
        public static async Task SendBlockedMail(RegisteredUser regUser, string originIp)
        {
            // OTP p = new OTP();
            // long Datetimenow = DateTime.UtcNow.ToFileTimeUtc();
            //OTP O = new OTP(x, Guid.NewGuid().ToByteArray());
            //long Datetimenow = DateTime.UtcNow.ToFileTimeUtc();
            //string token = O.GetCurrentOTP();
            //UIContext.RegisterToken(token, "originip", regUser.user_identifier);
            long   Datetimenow = DateTime.UtcNow.Ticks;
            string t           = regUser.RegistereduserId.ToString() + Guid.NewGuid().ToString();
            string tokens      = ClsFunction.GenerateResetToken(t + ":" + Datetimenow);
            string new_token   = Regex.Replace(tokens, "[^0-9a-zA-Z]+", "");
            string link        = ConfigurationManager.AppSettings["URL_BASE_ResetPassword"];
            string regLink     = string.Format(link, HttpUtility.UrlEncode(new_token));
            var    resetToken  = "<a href='" + regLink + "'>Activation Link</a>";

            RegistrationContext.ResetPasswordToken(regUser.RegistereduserId, new_token, originIp);

            var content = MailerContext.SelectEmailContent("ss");

            if (content == null)
            {
                content = new EmailTemplate()
                {
                    content = @"Hi [NAME], Your Account has been blocked.
                                <br/> Please use the below link to reset your account.<br/>[LINK]<br/>Please note this link will expire in 24 hours",
                    subject = "Your Account has been blocked"
                }
            }
            ;

            else if (string.IsNullOrEmpty(content.content))
            {
                content.content = @"Hi [USERNAME],Your Account has been blocked.
                                <br/>Please use the below OTP to reset your account.<br/>[LINK]<br/>Please note this OTP will expire in 24 hours";
                content.subject = content.subject == "" || content.subject == null ? "Invalid Logn Attempt" : content.subject;
            }
            //var resetToken = "<a href='" + resetTokenAction + (DateTime.UtcNow.ToFileTimeUtc() + ":" + regUser.username).GenerateResetToken() + "'>Activation Link</a>";

            await Mailer.SendMailAsync(new MailContent()
            {
                ccAddress = "",
                Content   = HttpUtility.UrlDecode(HttpUtility.HtmlDecode(content.content))
                            .Replace("[NAME]", regUser.First_name + regUser.Middle_name + regUser.Last_name)
                            .Replace("[USERNAME]", regUser.Username)
                            .Replace("[LINK]", ""),
                Email      = regUser.Email_address,
                Subject    = content.subject,
                TypeOfMail = 1
            }, regUser.Username, regUser.RegistereduserId);
        }
Ejemplo n.º 3
0
        public static async Task SendMail(RegisteredUser regUser)
        {
            //OTP otp = new OTP();
            //OTP otp;
            // OTP O = new OTP(x,Guid.NewGuid().ToByteArray());
            long Datetimenow = DateTime.UtcNow.Ticks;
            //string token = O.GetCurrentOTP();//OTPGeneration.GenerateOTP();
            // string t = otp.GetNextOTP();
            string t          = regUser.RegistereduserId.ToString() + Guid.NewGuid().ToString();
            string token      = ClsFunction.GenerateResetToken(t + ":" + Datetimenow);
            string new_token  = Regex.Replace(token, "[^0-9a-zA-Z]+", "");
            string link       = ConfigurationManager.AppSettings["URL_BASE_Register"];
            string regLink    = string.Format(link, HttpUtility.UrlEncode(new_token));
            var    resetToken = "<a href='" + regLink + "'>Activation Link</a>";

            RegistrationContext.RegisterToken(new_token, regUser.Registration_ip, regUser.RegistereduserId);

            var content = MailerContext.SelectEmailContent("ss");

            if (content == null)
            {
                content = new EmailTemplate()
                {
                    content = @"Hi [NAME], Your account has been created and your username is [USERNAME]
                        <br/>Please use the below link to activate your account.<br/>Your LINK is [LINK]<br/>Please note this link will expire in 24 hours",
                    subject = "Your account has been created"
                }
            }
            ;

            else if (string.IsNullOrEmpty(content.content))
            {
                content.content = @"Hi [NAME], Your account has been created and your username is [USERNAME]
                        <br/>Please use the below link to activate your account.<br/>Your LINK is [LINK]<br/>Please note this link will expire in 24 hours";
                content.subject = content.subject ?? "Your account has been created";
            }
            //var resetToken = "<a href='" + resetTokenAction + (DateTime.UtcNow.ToFileTimeUtc() + ":" + regUser.username).GenerateResetToken() + "'>Activation Link</a>";

            await Mailer.SendMailAsync(new MailContent()
            {
                ccAddress = "",
                Content   = HttpUtility.UrlDecode(HttpUtility.HtmlDecode(content.content))
                            .Replace("[NAME]", regUser.First_name + regUser.Middle_name + regUser.Last_name)
                            .Replace("[USERNAME]", regUser.Username)
                            .Replace("[LINK]", resetToken),
                Email      = regUser.Email_address,
                Subject    = content.subject,
                TypeOfMail = 1
            }, regUser.Username, regUser.RegistereduserId);
        }