public ActionResult ChangePassword(ChangePasswordModel model) { var userId = Convert.ToInt64(Session["userId"]); var userData = _readOnlyRepository.GetById <Account>(userId); var oldPasswordEncripted = EncriptacionMD5.Encriptar(model.OldPassword); if (userData.Password != oldPasswordEncripted) { Error("The old password is incorrect!!!"); ClearModel(model); return(View(model)); } userData.Password = EncriptacionMD5.Encriptar(model.NewPassword); _writeOnlyRepository.Update(userData); AddActivity("El usuario ha cambiado su contrasena"); Success("Password changed successfully!!"); ClearModel(model); return(View(model)); }
public ActionResult PasswordReset(string token) { if (token == "ErrorPostback") { Error("Link has expired!!!"); return(View()); } var fechaActual = DateTime.Now.Date; var data = token.Split(';'); var password = data[0]; var linkDate = data[1]; var currentDate = "" + fechaActual.Day + fechaActual.Month + fechaActual.Year; var currentDateMd5 = EncriptacionMD5.Encriptar(currentDate); var user = _readOnlyRepository.Query <Account>(a => a.Password == password); if (linkDate == currentDateMd5 && user.Any()) { return(View(new PasswordResetModel { UserId = user.FirstOrDefault().Id })); } return(RedirectToAction("PasswordReset", new { token = "ErrorPostBack" })); }
public ActionResult PasswordRecovery(PasswordRecoveryModel model) { var result = _readOnlyRepository.First <Account>(a => a.EMail == model.EMailAddress); if (result != null) { var fechaActual = DateTime.Now.Date; var pass = result.Password; var data = "" + fechaActual.Day + fechaActual.Month + fechaActual.Year; var token = pass + ";" + EncriptacionMD5.Encriptar(data); //var url = "http://Galeria-1.apphb.com/PasswordReset/PasswordReset"; var url = "http://Galeriaclase.apphb.com/PasswordReset/PasswordReset"; var emailBody = new StringBuilder("<b>Go to the following link to change your password: </b>"); emailBody.Append("<br/>"); emailBody.Append("<br/>"); emailBody.Append("<b>" + url + "?token=" + token + "<b>"); emailBody.Append("<br/>"); emailBody.Append("<br/>"); emailBody.Append("<b>This link is only valid through " + fechaActual.Day + "/" + fechaActual.Month + "/" + fechaActual.Year + "</b>"); if (MailSender.SendEmail(model.EMailAddress, "Password Recovery", emailBody.ToString())) { return(Cancel()); } Error("E-Mail failed to be sent, please try again!!!"); return(View(model)); } Error("E-Mail address is not registered in this site!!!"); return(View(model)); }
public ActionResult PasswordReset(PasswordResetModel model) { var newPassword = EncriptacionMD5.Encriptar(model.Password); var user = _readOnlyRepository.GetById <Account>(model.UserId); user.Password = newPassword; _writeOnlyRepository.Update <Account>(user); return(RedirectToAction("LogIn", "Account")); }
public ActionResult LogIn(AccountLoginModel model) { var passwordEncripted = EncriptacionMD5.Encriptar(model.Password); var result = _readOnlyRepository.First <Account>(x => x.EMail == model.EMail && x.Password == passwordEncripted); if (result != null) { if (!CheckPassword(result, passwordEncripted)) { Error("Contraseña invalida"); return(View()); } if (result.IsBlocked) { Error( "Your account has been blocked by the Admin due to violation of the terms of usage of this site!"); return(View()); } if (!result.Isconfirmed) { Error( "Your account has not been confirmed!"); return(View()); } if (result.IsArchived) { Error("Your account is inactive, to activate it again send an e-mail to [email protected]"); return(View()); } var roles = result.IsAdmin ? new List <string>(new[] { "Admin" }) : new List <string>(new[] { "User" }); FormsAuthentication.SetAuthCookie(model.EMail, model.RememberMe); SetAuthenticationCookie(model.EMail, roles); if (result.IsAdmin) { return(RedirectToAction("RegisteredUsersList", "RegisteredUsersList")); } Session["ActualPath"] = string.Empty; Session["ActualFolder"] = string.Empty; return(RedirectToAction("ListAllContent", "Disk")); } Error("E-Mail or Password is incorrect!!!"); return(View()); }
private bool checkCredenciales(string userName, string password) { var account = _readOnlyRepository.First <Account>(x => x.EMail == userName); if (checkCuenta(account)) { if (account.Password == EncriptacionMD5.Encriptar(password)) { return(true); } } return(false); }
private string CreateTokenForUser(string userName) { var account = _readOnlyRepository.First <Account>(x => x.EMail == userName); if (checkCuenta(account)) { var tokenString = EncriptacionMD5.Encriptar(userName) + GetHashCode(); var key = new ApiKeys(); key.ExpirationTime = MinutesPermission(); key.UserId = account.Id; key.Token = tokenString; _writeOnlyRepository.Create(key); return(key.Token); } return("Credenciales invalidas"); }
public ActionResult AccountSignUp(AccountSignUpModel model) { var result = _readOnlyRepository.Query <Account>(a => a.EMail == model.EMail); if (result.Any()) { Error("Email account is already registered in this site!!!"); return(View(model)); } var account = Mapper.Map <Account>(model); account.IsArchived = false; account.IsAdmin = false; account.IsBlocked = false; account.SpaceLimit = 2408; account.Password = EncriptacionMD5.Encriptar(model.Password); account.Isconfirmed = false; account.BucketName = string.Format("mdp.{0}", Guid.NewGuid()); //var account = new Account //{ // Name = accountModel.Name, // LastName = accountModel.LastName, // EMail = accountModel.EMail, // IsArchived = false, // IsBlocked = false, // SpaceLimit = 500, // UsedSpace = 0, // Password = EncriptacionMD5.Encriptar(accountModel.Password) //}; //account.AddRole(new Role{Name = "User",IsArchived = false}); var createdAccount = _writeOnlyRepository.Create(account); var token = Convert.ToInt64(Session["userReferralId"]); if (token != 0) { var userReferring = _readOnlyRepository.GetById <Account>(token); userReferring.Referrals.Add(createdAccount); _writeOnlyRepository.Update(userReferring); } var serverFolderPath = Server.MapPath("~/App_Data/UploadedFiles/" + account.EMail); Directory.CreateDirectory(serverFolderPath); var newBucket = new PutBucketRequest { BucketName = account.BucketName }; AWSClient.PutBucket(newBucket); var putFolder = new PutObjectRequest { BucketName = account.BucketName, Key = "Shared/", ContentBody = string.Empty }; AWSClient.PutObject(putFolder); var sharedDirectory = serverFolderPath + "/Shared"; Directory.CreateDirectory(sharedDirectory); //var serverFolderPath = Server.MapPath("~/App_Data/UploadedFiles/" + account.EMail); //Directory.CreateDirectory(serverFolderPath); //var sharedDirectory =serverFolderPath + "/Shared"; //Directory.CreateDirectory(sharedDirectory); if (createdAccount.Files == null) { createdAccount.Files = new List <Domain.File>(); } if (createdAccount.History == null) { createdAccount.History = new List <Actividades>(); } createdAccount.Files.Add(new Domain.File { CreatedDate = DateTime.Now, FileSize = 0, IsArchived = false, IsDirectory = true, Name = "Shared", Url = "", Type = "", ModifiedDate = DateTime.Now }); _writeOnlyRepository.Update(createdAccount); AddActivity("El usuario se registro.", createdAccount); // ESTOOOOOOO #region EnvioCorreoParaNotificacion var fechaActual = DateTime.Now.Date; var pass = result.FirstOrDefault().Id; var data = "" + fechaActual.Day + fechaActual.Month + fechaActual.Year; var tokenConfir = pass + ";" + EncriptacionMD5.Encriptar(data); //var url = "http://minidropbox-1.apphb.com/PasswordReset/PasswordReset"; var url = "http://minidropboxclase.apphb.com/Account/Confirmed"; var emailBody = new StringBuilder("<b>Confirm your account of MiniDropbox</b>"); emailBody.Append("<br/>"); emailBody.Append("<br/>"); emailBody.Append("<b>" + url + "?token=" + tokenConfir + "<b>"); emailBody.Append("<br/>"); emailBody.Append("<br/>"); emailBody.Append("<b>This link is only valid through " + DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + "</b>"); if (MailSender.SendEmail(model.EMail, "Confirm your account of MiniDropbox", emailBody.ToString())) { return(Cancelar()); } Error("E-Mail failed to be sent, please try again!!!"); return(View(model)); #endregion return(Cancelar()); }
public ActionResult AccountSignUp(AccountSignUpModel model) { var result = _readOnlyRepository.Query <Account>(a => a.EMail == model.EMail); if (result.Any()) { Error("Email account is already registered in this site!!!"); return(View(model)); } var account = Mapper.Map <Account>(model); account.IsArchived = false; account.IsAdmin = false; account.IsBlocked = false; account.Password = EncriptacionMD5.Encriptar(model.Password); account.Isconfirmed = false; var createdAccount = _writeOnlyRepository.Create(account); var token = Convert.ToInt64(Session["userReferralId"]); if (token != 0) { var userReferring = _readOnlyRepository.GetById <Account>(token); userReferring.Referrals.Add(createdAccount); _writeOnlyRepository.Update(userReferring); } var serverFolderPath = Server.MapPath("~/App_Data/UploadedFiles/" + account.EMail); Directory.CreateDirectory(serverFolderPath); // ESTOOOOOOO #region EnvioCorreoParaNotificacion var fechaActual = DateTime.Now.Date; var pass = result.FirstOrDefault().Id; var data = "" + fechaActual.Day + fechaActual.Month + fechaActual.Year; var tokenConfir = pass + ";" + EncriptacionMD5.Encriptar(data); //var url = "http://Galeria-1.apphb.com/PasswordReset/PasswordReset"; var url = "http://Galeriaclase.apphb.com/Account/Confirmed"; var emailBody = new StringBuilder("<b>Confirm your account of Galeria</b>"); emailBody.Append("<br/>"); emailBody.Append("<br/>"); emailBody.Append("<b>" + url + "?token=" + tokenConfir + "<b>"); emailBody.Append("<br/>"); emailBody.Append("<br/>"); emailBody.Append("<b>This link is only valid through " + DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + "</b>"); if (MailSender.SendEmail(model.EMail, "Confirm your account of Galeria", emailBody.ToString())) { return(Cancelar()); } Error("E-Mail failed to be sent, please try again!!!"); return(View(model)); #endregion return(Cancelar()); }
public ActionResult Confirmed(string token) { if (token == "ErrorPostback") { Error("Link has expired!!!"); return(RedirectToAction("LogIn")); } var fechaActual = DateTime.Now.Date; var data = token.Split(';'); var id = data[0]; var linkDate = data[1]; var currentDate = "" + fechaActual.Day + fechaActual.Month + fechaActual.Year; var currentDateMd5 = EncriptacionMD5.Encriptar(currentDate); var user = _readOnlyRepository.First <Account>(a => a.Id.ToString() == id); var model = new AccountLoginModel(); if (user != null) { model.EMail = user.EMail; } if (user != null) { model.Password = user.Password; } if (linkDate == currentDateMd5 && user != null) { var result = _readOnlyRepository.First <Account>(x => x.EMail == model.EMail && x.Password == model.Password); if (result != null) { if (result.IsBlocked) { Error( "Your account has been blocked by the Admin due to violation of the terms of usage of this site!"); return(RedirectToAction("LogIn")); } if (result.Isconfirmed) { Error("Your account has already been confirmed"); return(RedirectToAction("LogIn")); } if (result.IsArchived) { Error("Your account is inactive, to activate it again send an e-mail to [email protected]"); return(RedirectToAction("LogIn")); } var roles = result.IsAdmin ? new List <string>(new[] { "Admin" }) : new List <string>(new[] { "User" }); FormsAuthentication.SetAuthCookie(model.EMail, model.RememberMe); SetAuthenticationCookie(model.EMail, roles); Session["ActualPath"] = result.EMail; Session["ActualFolder"] = result.EMail; result.Isconfirmed = true; _writeOnlyRepository.Update <Account>(result); Success("Your Account it is Confirmed"); return(RedirectToAction("ListAllContent", "Disk")); } return(RedirectToAction("Confirmed", new { token = "ErrorPostBack" })); } return(RedirectToAction("LogIn")); }