public ActionResult Registration(RegisteredUser model) { if (model != null) { model.Country = "United States"; model.Mbile_country_code = "+1"; model.Province = "Massachussets"; model.Email_address = model.Username; model.Registration_ip = ClsFunction.GetVisitorIPAddress(); var res = FuncRegister(model); if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.RegistrationSucces).ToString()) { TempData["Success"] = res.ErrorMessage; return(Json(new { success = true, message = "S|" + res.ErrorMessage }, JsonRequestBehavior.DenyGet)); } else if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.UserInActive).ToString()) { return(Json(new { success = false, message = "U|" + res.ErrorMessage }, JsonRequestBehavior.DenyGet)); } else if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.UserExists).ToString()) { return(Json(new { success = false, message = "UE|" + res.ErrorMessage }, JsonRequestBehavior.DenyGet)); } else { return(Json(new { success = false, message = "F|" + res.ErrorMessage }, JsonRequestBehavior.DenyGet)); } } return(Json(new { success = false, message = "F|" + "Something went wrong" }, JsonRequestBehavior.DenyGet)); }
//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 = "" }); } }
public async Task <ActionResult> UpdatePassword([Bind(Include = "password,confirm,token")] string password, string confirm, string token) { ResetPasswordModel model = new ResetPasswordModel(); model.password = password; model.used_on_ip = ClsFunction.GetVisitorIPAddress(); model.token = token; var res = RegistrationProvider.ResetPassword(model.password, model.token, model.used_on_ip); var MODEL = new ResetPasswordModel(); if (res == "S") { return(Json(new { success = true, message = "Successfully done!", data = MODEL }, JsonRequestBehavior.DenyGet)); } else if (res == "LE") { return(Json(new { success = false, message = "Link has been expired" }, JsonRequestBehavior.DenyGet)); } else { return(Json(new { success = false, message = "Resetting Password Failed" }, JsonRequestBehavior.DenyGet)); } return(Json(new { success = false, message = "Resetting Password Failed" }, JsonRequestBehavior.DenyGet)); }
public async Task <ActionResult> Confirmation([Bind(Include = "id")] string id) { string usedon_ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; string UsedOnIp = ClsFunction.GetVisitorIPAddress(); string Token = id; if (!string.IsNullOrEmpty(UsedOnIp) && !string.IsNullOrEmpty(Token)) { var result = RegistrationProvider.ActivateRegistration(Token, UsedOnIp); if (result == "S") { TempData["Success"] = "Registration Activated"; return(RedirectToAction("Success", "Home")); } else if (result == "LE") { TempData["Error"] = "Link is Expired"; return(RedirectToAction("Error", "Home")); } else { TempData["Error"] = "Failed"; return(RedirectToAction("Error", "Home")); } } TempData["Error"] = "Sonething went Wrong Please try again!"; return(RedirectToAction("Error", "Home")); }
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); }
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); }
public ActionResult ForgotPassword(ForgotPasswordModel model) { try { model.deviceId = ClsFunction.GetVisitorIPAddress(); var res = RegistrationProvider.GetUsersNamecheck(model.username, model.deviceId); if (res) { return(Json(new { title = "ForgotPassword", success = true, message = "Email has been sent to you with the Link" }, JsonRequestBehavior.DenyGet)); } else { return(Json(new { title = "ForgotPassword", success = false, message = "User Does not Exist" }, JsonRequestBehavior.DenyGet)); } } catch (Exception ex) { return(Json(new { title = "ForgotPassword", success = false, message = "Something went Wrong Please try again" }, JsonRequestBehavior.DenyGet)); } }
public async Task <ActionResult> Login([Bind(Include = "user,word,rememberme")] string user, string word, string rememberme) { try { HttpContext.User = null; FormsAuthentication.SignOut(); LoginModel model = new LoginModel(); model.Username = user; model.Password = word; model.IpAddress = ClsFunction.GetVisitorIPAddress(); model.Type = "WEB"; bool RememberMe = false; if (rememberme != null) { RememberMe = true; } else { RememberMe = false; } Response res = new Response(); res = RegistrationProvider.LoginFunc(model); if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.LoginSuccess).ToString()) { FormsAuthentication.SetAuthCookie(user, RememberMe); Session["LoginAttempts"] = 0; return(Json(new { title = "Login", success = true, message = res.ErrorMessage, failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } else if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.FirstLogin).ToString()) { FormsAuthentication.SetAuthCookie(user, RememberMe); Session["LoginAttempts"] = 0; return(Json(new { title = "Login", success = true, message = res.ErrorMessage, failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } else if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.LoginFailure).ToString()) { if (Session["LoginAttempts"] == null) { Session["LoginAttempts"] = 1; } else { Session["LoginAttempts"] = 1 + (int)Session["LoginAttempts"]; } return(Json(new { title = "Login", success = false, message = res.ErrorMessage, failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } else if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.InvalidUserNamePass).ToString()) { if (Session["LoginAttempts"] == null) { Session["LoginAttempts"] = 1; } else { Session["LoginAttempts"] = 1 + (int)Session["LoginAttempts"]; } return(Json(new { title = "Login", success = false, message = res.ErrorMessage, failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } else if (res.ErrorCode == ((int)ErrorProvider.ErrorCode.UserNotExist).ToString()) { if (Session["LoginAttempts"] == null) { Session["LoginAttempts"] = 1; } else { Session["LoginAttempts"] = 1 + (int)Session["LoginAttempts"]; } return(Json(new { title = "Login", success = false, message = res.ErrorMessage, failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } else { if (Session["LoginAttempts"] == null) { Session["LoginAttempts"] = 1; } else { Session["LoginAttempts"] = 1 + (int)Session["LoginAttempts"]; } return(Json(new { title = "Login", success = false, message = "Something Went Wrong Please Try again", failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } } catch (Exception ex) { if (Session["LoginAttempts"] == null) { Session["LoginAttempts"] = 1; } else { Session["LoginAttempts"] = 1 + (int)Session["LoginAttempts"]; } return(Json(new { title = "Login", success = true, message = "Something went wrong Please try again later", failcount = Session["LoginAttempts"].ToString() }, JsonRequestBehavior.DenyGet)); } }