public async Task <JsonResult> SendCode(string id) { try { var userStore = _membershipTools.NewUserStore(); var user = await userStore.FindByIdAsync(id); if (user == null) { return(Json(new ResponseData() { message = "Kullanıcı bulunamadı.", success = false })); } if (user.EmailConfirmed) { return(Json(new ResponseData() { message = "Kullanıcı zaten e-postasını onaylamış.", success = false })); } user.ActivationCode = StringHelpers.GetCode(); await userStore.UpdateAsync(user); userStore.Context.SaveChanges(); var uri = new UriBuilder() { Scheme = Uri.UriSchemeHttps }; var hostComponents = Request.Host.ToUriComponent(); string SiteUrl = uri.Scheme + System.Uri.SchemeDelimiter + hostComponents; var emailService = new EmailService(); var body = $"Merhaba <b>{user.Name} {user.Surname}</b><br>Hesabınızı aktif etmek için aşağıdaki linke tıklayınız.<br> <a href='{SiteUrl}/account/activation?code={user.ActivationCode}' >Aktivasyon Linki </a> "; await emailService.SendAsync(new EmailModel() { Body = body, Subject = "Sitemize Hoşgeldiniz" }, user.Email); return(Json(new ResponseData() { message = "Kullanıcıya yeni aktivasyon maili gönderildi.", success = true })); } catch (Exception ex) { return(Json(new ResponseData() { message = $"Bir hata oluştu: {ex.Message}", success = false })); } }
public async Task <ActionResult> RecoverPassword(RecoverPasswordVM model) { try { var userStore = _membershipTools.NewUserStore(); var userManager = _membershipTools.UserManager; var user = await userStore.FindByEmailAsync(model.Email); if (user == null) { ModelState.AddModelError(string.Empty, $"{model.Email} mail adresine kayıtlı bir üyeliğe erişilemedi"); return(View(model)); } var newPassword = StringHelpers.GetCode().Substring(0, 6) + "A0*"; var hashPassword = userManager.PasswordHasher.HashPassword(user, newPassword); await userStore.SetPasswordHashAsync(user, hashPassword); var result = userStore.Context.SaveChanges(); if (result == 0) { var errorVM = new ErrorVM() { Text = $"Bir hata oluştu", ActionName = "RecoverPassword", ControllerName = "Account", ErrorCode = "500" }; TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM); return(RedirectToAction("Error500", "Home")); } var emailService = new EmailService(); var body = $"Merhaba <b>{user.Name} {user.Surname}</b><br>Hesabınızın parolası sıfırlanmıştır<br> Yeni parolanız: <b>{newPassword}</b> <p>Yukarıdaki parolayı kullanarak sitemize giriş yapabilirsiniz.</p>"; emailService.Send(new EmailModel() { Body = body, Subject = $"{user.UserName} Şifre Kurtarma" }, user.Email); } catch (Exception ex) { var errorVM = new ErrorVM() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "RecoverPassword", ControllerName = "Account", ErrorCode = "500" }; TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM); return(RedirectToAction("Error500", "Home")); } TempData["Message"] = $"{model.Email} mail adresine yeni şifre gönderildi."; return(View()); }
public async Task <JsonResult> RolGuncelle(string id, string rolename, string oldrole) { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(id); try { userManager.RemoveFromRole(user.Id, oldrole); userManager.AddToRole(user.Id, rolename); user.PreRole = oldrole; await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = "Hata oluştu" }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> UpdatePassword(ProfilePasswordViewModel model) { if (model.passwordModel.NewPassword != model.passwordModel.NewPasswordConfirm) { ModelState.AddModelError(string.Empty, "Şifreler uyuşmuyor"); return(View("Profile", model)); } try { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(model.profileModel.Id); user = userManager.Find(user.UserName, model.passwordModel.OldPassword); if (user == null) { ModelState.AddModelError(string.Empty, "Şifrenizi yanlış girdiniz"); return(View("Profile", model)); } await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.passwordModel.NewPassword)); await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); HttpContext.GetOwinContext().Authentication.SignOut(); return(RedirectToAction("Profile")); } catch (Exception ex) { ViewBag.sonuc = "günceleştirilemedi" + ex.Message; return(View("Profile", model)); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapperConfig.RegisterMappings(); var userManager = MembershipTools.NewUserManager(); var userStore = MembershipTools.NewUserStore(); var roller = Enum.GetNames(typeof(IdentityRoles)); var roleManager = MembershipTools.NewRoleManager(); foreach (var rol in roller) { if (!roleManager.RoleExists(rol)) { roleManager.Create(new Role() { Name = rol, }); } } if (!userStore.Users.Any()) { DataHelper.DataEkle(); } }
public async Task <ActionResult> ChangePassword(ProfileViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Profile")); } var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); var checkuser = userManager.Find(user.UserName, model.OldPassword); if (checkuser == null) { ModelState.AddModelError(string.Empty, "Mevcut şifreniz yanlış"); return(RedirectToAction("Profile")); } await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.ConfirmPassword)); await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); await SiteSettings.SendMail(new MailModel() { Message = $"Merhaba {user.UserName}, </br> Şifreniz Panelden değiştirilmiştir.", Subject = "Şifreniz Değişti!", To = user.Email }); return(RedirectToAction("Logout")); }
public async Task <ActionResult> ChangePassword(ProfilePasswordMultiViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Profile", "Account")); } try { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = await userManager.FindByIdAsync(HttpContext.User.Identity.GetUserId()); user = await userManager.FindAsync(user.UserName, model.ChangePasswordViewModel.OldPassword); if (user == null) { ModelState.AddModelError("OldPassword", "Mevcut şifreniz hatalı"); return(View("Profile")); } await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.ChangePasswordViewModel.Password)); await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); HttpContext.GetOwinContext().Authentication.SignOut(); return(RedirectToAction("Profile")); } catch (Exception ex) { ModelState.AddModelError("", $"Güncelleme işleminde bir hata oluştu.{ex.Message}"); return(View("Profile")); } }
public ActionResult Activation(string code) { try { var userStore = MembershipTools.NewUserStore(); var user = userStore.Users.FirstOrDefault(x => x.ActivationCode == code); if (user != null) { if (user.EmailConfirmed) { ViewBag.Message = $"<span class='alert alert-success'>Bu hesap daha önce aktive edilmiştir.</span>"; } else { user.EmailConfirmed = true; userStore.Context.SaveChanges(); ViewBag.Message = $"<span class='alert alert-success'>Aktivasyon işleminiz başarılı</span>"; } } else { ViewBag.Message = $"<span class='alert alert-danger'>Aktivasyon başarısız</span>"; } } catch (Exception ex) { ViewBag.Message = "<span class='alert alert-danger'>Aktivasyon işleminde bir hata oluştu</span>"; } return(View()); }
public async Task <ActionResult> Profile(ProfilePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(model.ProfileModel.Id); user.Name = model.ProfileModel.Name; user.Surname = model.ProfileModel.Surname; if (user.Email != model.ProfileModel.Email) { user.Email = model.ProfileModel.Email; if (HttpContext.User.IsInRole("Admin")) { userManager.RemoveFromRole(user.Id, "Admin"); } else if (HttpContext.User.IsInRole("User")) { userManager.RemoveFromRole(user.Id, "User"); } userManager.AddToRole(user.Id, "Passive"); user.ActivationCode = Guid.NewGuid().ToString().Replace("-", ""); string siteUrl = Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); await SiteSettings.SendMail(new MailModel { To = user.Email, Subject = "Personel Yönetimi - Aktivasyon", Message = $"Merhaba {user.Name} {user.Surname} <br/>Email adresinizi <b>değiştirdiğiniz</b> için hesabınızı tekrar aktif etmelisiniz. <a href='{siteUrl}/Account/Activation?code={user.ActivationCode}'>Aktivasyon Kodu</a>" }); } await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); var model1 = new ProfilePasswordViewModel() { ProfileModel = new ProfileViewModel { Id = user.Id, Email = user.Email, Name = user.Name, Surname = user.Surname, UserName = user.UserName } }; ViewBag.sonuc = "Bilgileriniz güncelleşmiştir"; return(View(model1)); } catch (Exception ex) { ViewBag.sonuc = ex.Message; return(View(model)); } }
protected List <SelectListItem> GetUserList() { var data = new List <SelectListItem>(); MembershipTools.NewUserStore().Users .ToList() .ForEach(x => { data.Add(new SelectListItem() { Text = $"{x.Name} {x.Surname}", Value = x.Id }); }); //veya //var users = MembershipTools.NewUserStore().Users; //var data = new List<SelectListItem>(); //foreach (var user in users) //{ // data.Add(new SelectListItem() // { // Text = $"{user.Name} {user.Surname}", // Value = user.Id, // }); //} return(data); }
public async Task <ActionResult> Activation(string code) { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var sonuc = userStore.Context.Set <ApplicationUser>().FirstOrDefault(x => x.ActivationCode == code); if (sonuc == null) { ViewBag.sonuc = "Aktivasyon işlemi başarısız"; return(View()); } sonuc.EmailConfirmed = true; await userStore.UpdateAsync(sonuc); await userStore.Context.SaveChangesAsync(); userManager.RemoveFromRole(sonuc.Id, "Passive"); userManager.AddToRole(sonuc.Id, "User"); ViewBag.sonuc = $"Merhaba{sonuc.Name} {sonuc.SurName} kayıt aktivaston işleminiz başarılı olmuştur."; await SiteSettings.SendMail(new MailModel() { To = sonuc.Email, Message = ViewBag.sonuc.ToString(), Subject = "Aktivasyon", Bcc = "*****@*****.**" }); return(View()); }
public async Task <ActionResult> EditUser(UsersViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var roles = MembershipTools.NewRoleManager().Roles.ToList(); var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(model.UserId); if (user == null) { return(View("Index")); } user.UserName = model.UserName; user.Name = model.Name; user.SurName = model.Surname; user.Salary = model.Salary; user.Email = model.Email; if (model.RoleId != user.Roles.ToList().FirstOrDefault().RoleId) { var yenirol = roles.First(x => x.Id == model.RoleId).Name; userManager.AddToRole(model.UserId, yenirol); var eskirol = roles.First(x => x.Id == user.Roles.ToList().FirstOrDefault().RoleId).Name; userManager.RemoveFromRole(model.UserId, eskirol); } await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); return(RedirectToAction("EditUser", new { id = model.UserId })); }
public async Task <ActionResult> RecoverPassword(string email) { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); try { var sonuc = userStore.Context.Set <ApplicationUser>().FirstOrDefault(x => x.Email == email); if (sonuc == null) { ViewBag.sonuc = "E mail adresiniz sisteme kayıtlı değil"; return(View()); } var randomPass = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6); await userStore.SetPasswordHashAsync(sonuc, userManager.PasswordHasher.HashPassword(randomPass)); await SiteSettings.SendMail(new MailModel() { To = sonuc.Email, Subject = "Şifreniz Değişti", Message = $"Merhaba {sonuc.Ad} {sonuc.Soyad} <br/>Yeni Şifreniz : <b>{randomPass}</b>" }); ViewBag.sonuc = "Email adresinize yeni şifreniz gönderilmiştir"; return(View()); } catch (Exception) { ViewBag.sonuc = "Sistemsel bir hata oluştu. Tekrar deneyiniz"; return(View()); } }
public async Task <ActionResult> UpdatePassword(ProfileViewModel model) { if (model.YeniSifre != model.YeniSifreTekrar) { ModelState.AddModelError(string.Empty, "Şifreler uyuşmuyor"); return(View("Profile")); } try { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); user = userManager.Find(user.UserName, model.EskiSifre); if (user == null) { ModelState.AddModelError(string.Empty, "Mevcut şifreniz yanlış girildi"); return(View("Profile")); } await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.YeniSifre)); await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); HttpContext.GetOwinContext().Authentication.SignOut(); return(RedirectToAction("Profile")); } catch (Exception ex) { ViewBag.sonuc = "Güncelleştirme işleminde bir hata oluştu. " + ex.Message; throw; } }
public async Task <ActionResult> RecoverPassword(string email) { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var sonuc = userStore.Context.Set <ApplicationUser>().FirstOrDefault(x => x.Email == email); if (sonuc == null) { ViewBag.sonuc = "email adresiniz kayıtlı değil"; return(View()); } var randomPas = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6); await userStore.SetPasswordHashAsync(sonuc, userManager.PasswordHasher.HashPassword(randomPas)); await userStore.UpdateAsync(sonuc); await userStore.Context.SaveChangesAsync(); await SiteSettings.SendMail(new MailModel() { To = sonuc.Email, Subject = "Şifreniz değiştirildi", Message = $"Merhaba {sonuc.Name} {sonuc.SurName} yeni şifreniz:<b>{randomPas}</b> olmuştur" }); ViewBag.sonuc = "Email adresinize yeni şifre gönderilmiştir"; return(View()); }
public async Task <ActionResult> Profile(ProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); if (user.Email != model.Email) { userManager.AddToRole(user.Id, "Passive"); user.Email = model.Email; user.EmailConfirmed = false; if (HttpContext.User.IsInRole("User")) { userManager.RemoveFromRole(user.Id, "User"); user.PreRole = "User"; } else if (HttpContext.User.IsInRole("Teknisyen")) { userManager.RemoveFromRole(user.Id, "Teknisyen"); user.PreRole = "Teknisyen"; } else if (HttpContext.User.IsInRole("Admin")) { userManager.RemoveFromRole(user.Id, "Admin"); user.PreRole = "Admin"; } var aktivasyonKodu = Guid.NewGuid().ToString().Replace("-", ""); user.ActivationCode = aktivasyonKodu; string SiteUrl = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); await SiteSettings.SendMail(new MailModel() { To = user.Email, Subject = "Hesabınızı Aktifleştirmeniz Gerekiyor", Message = $"Merhaba {user.UserName}, </br> Sistemi Kullanabilmek için Hesabınız tekrar aktifleştirmeniz gerekiyor. <br/> Hesabınızı aktifleştirmek için <a href='{SiteUrl}/Account/Activation?code={aktivasyonKodu}'>Aktivasyon Kodu</a>" }); var authManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authManager.SignIn(new AuthenticationProperties() { IsPersistent = true }, userIdentity); } user.Name = model.Name; user.Surname = model.Surname; user.PhoneNumber = model.PhoneNumber; await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); return(RedirectToAction("Profile")); }
public Dictionary <string, string> CalisanlariGetir() { var calisanlar = MembershipTools.NewUserStore().Users .Select(x => new { id = x.Id, nameSurname = x.Name + " " + x.Surname }) .ToDictionary(x => x.id, x => x.nameSurname); return(calisanlar); }
public ResponseModel UpdatePassword([FromBody] ChangePasswordViewModel value) { if (value.NewPassword != value.NewPasswordConfrim) { return new ResponseModel { success = false, message = "Şifreler Uyuşmuyor" } } ; var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(value.Id); if (user == null) { return new ResponseModel { success = false, message = "Kullanıcı bulunamadı" } } ; try { var sonuc = userManager.ChangePassword(value.Id, value.OldPassword, value.NewPassword); if (sonuc.Succeeded) { return new ResponseModel() { success = true, message = "Şifre güncellenmiştir" } } ; else { return new ResponseModel { success = false, message = "Şifre güncelleme işleminde hata" } }; } catch (Exception ex) { return(new ResponseModel { success = false, message = $"Şifre güncelleme işleminde hata: {ex.Message}" }); } } } }
public async Task <JsonResult> UploadAvatar() { if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { string dosyayolu = string.Empty; try { var foto = System.Web.HttpContext.Current.Request.Files["myAvatar"]; string fileName = Path.GetFileNameWithoutExtension(foto.FileName); string extName = Path.GetExtension(foto.FileName); fileName += Guid.NewGuid().ToString().Replace("-", ""); fileName = SiteSettings.UrlFormatConverter(fileName); dosyayolu = Server.MapPath("../Upload/Avatars/") + fileName + extName; foto.SaveAs(dosyayolu); WebImage img = new WebImage(dosyayolu); img.Resize(200, 200, false); img.AddTextWatermark("Wissen", "RoyalBlue", opacity: 95, fontSize: 25, fontFamily: "Verdana"); img.Save(dosyayolu); var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); if (!string.IsNullOrEmpty(user.AvatarPath)) { var silinecekResim = Server.MapPath(user.AvatarPath); System.IO.File.Delete(silinecekResim); } user.AvatarPath = "../Upload/Avatars/" + fileName + extName; await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); return(Json(new { success = true, path = user.AvatarPath }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, errmessage = ex.Message }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = false, errmessage = "Hata Oluştu" }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Delete(string id) { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = await userManager.FindByIdAsync(id); await userManager.DeleteAsync(user); return(RedirectToAction("EditUsers", "Account")); }
public ActionResult EditUsers() { var popular = new Repository.ArticleRepo().Queryable().Where(x => x.Confirmed == true).OrderByDescending(x => x.LikeCount).Take(5).ToList(); ViewBag.popular = popular; var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var model = userManager.Users.ToList(); return(View(model)); }
public async Task <ActionResult> RecoverPassword(string recover) { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindByEmail(recover); var user2 = userManager.FindByName(recover); string newpass = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 6); if (user == null && user2 == null) { ModelState.AddModelError(string.Empty, "Kullanıcı Bulunamadı"); return(View()); } else if (user != null) { await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(newpass)); await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); await SiteSettings.SendMail(new MailModel() { To = user.Email, Subject = "Yeni Parolanız", Message = $"Merhaba {user.UserName} </br>Yeni Parolanız: <strong>{newpass}</strong></br>" }); return(RedirectToAction("Login", "Account")); } else if (user2 != null) { await userStore.SetPasswordHashAsync(user2, userManager.PasswordHasher.HashPassword(newpass)); await userStore.UpdateAsync(user2); await userStore.Context.SaveChangesAsync(); await SiteSettings.SendMail(new MailModel() { To = user2.Email, Subject = "Yeni Parolanız", Message = $"Merhaba {user2.UserName} </br>Yeni Parolanız: <strong>{newpass}</strong></br>" }); return(RedirectToAction("Login", "Account")); } else { return(View()); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var roller = Enum.GetNames(typeof(Roller)); var roleManager = MembershipTools.NewRoleManager(); foreach (var rol in roller) { if (!roleManager.RoleExists(rol)) { roleManager.Create(new Role() { Name = rol }); } } var userStore = MembershipTools.NewUserStore(); var userManager = MembershipTools.NewUserManager(); if (!userStore.Users.Any()) { var adminUser = new User() { UserName = "******", Name = "admin", Surname = "user" }; userManager.Create(adminUser, "admin1234"); userManager.AddToRole(adminUser.Id, "Admin"); for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { var otherUser = new User() { UserName = $"user_{i + 1}_{j + 1}", Name = $"user_{i + 1}_{j + 1}", Surname = "user" }; userManager.Create(otherUser, $"user_{i + 1}_{j + 1}"); userManager.AddToRole(otherUser.Id, $"Role{i + 1}"); } } } }
public async Task <ActionResult> Profile(ProfilePasswordMultiViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = await userManager.FindByIdAsync(HttpContext.User.Identity.GetUserId()); user.Name = model.ProfileViewModel.Name; user.Surname = model.ProfileViewModel.Surname; user.Bio = model.ProfileViewModel.Bio; user.Email = model.ProfileViewModel.Email; if (model.ProfileViewModel.Photo != null && model.ProfileViewModel.Photo.ContentLength > 0) { string fileName = Path.GetFileNameWithoutExtension(model.ProfileViewModel.Photo.FileName); string extensionName = Path.GetExtension(model.ProfileViewModel.Photo.FileName); fileName = SiteSettings.UrlFormatConverter(fileName); fileName += Guid.NewGuid().ToString().Replace("-", ""); var directoryPath = Server.MapPath("~/Uploads/ProfilePhotos/"); var filePath = Server.MapPath("~/Uploads/ProfilePhotos/" + fileName + extensionName); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } model.ProfileViewModel.Photo.SaveAs(filePath); WebImage img = new WebImage(filePath); img.Resize(800, 800, false); img.AddTextWatermark("Murat Bircan Blog", fontColor: "antiquewhite", fontSize: 18, fontFamily: "Verdana"); img.Save(filePath); if (!string.IsNullOrEmpty(user.PhotoURL) && user.PhotoURL != "/images/user.png") { System.IO.File.Delete(Server.MapPath(user.PhotoURL)); } user.PhotoURL = $@"/Uploads/ProfilePhotos/{fileName}{extensionName}"; } await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); return(RedirectToAction("Profile", "Account")); } catch (Exception ex) { ModelState.AddModelError("", $"Güncelleme sırasında bir hata oluştu.{ex.Message}"); return(View("Profile")); } }
// GET: Home public ActionResult Index() { //if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated) // return RedirectToAction("Logout", "Account"); if (!User.IsInRole("User") && User.Identity.IsAuthenticated) { ViewBag.pendingFailureCount = new FailureRepo().GetAll().Where(x => x.OperationStatus == Models.Enums.OperationStatuses.Pending).Count(); ViewBag.availableTechnicianCount = MembershipTools.NewUserStore().Users.Where(x => x.TechnicianStatus == Models.Enums.TechnicianStatuses.Available).Count(); } return(View()); }
protected List <SelectListItem> GetUserList() { var data = new List <SelectListItem>(); MembershipTools.NewUserStore().Users .ToList() .ForEach(x => { data.Add(new SelectListItem() { Text = $"{x.Name} {x.Surname}", Value = x.Id }); }); return(data); }
public async Task <ActionResult> ResendActivation() { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); string SiteUrl = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); await SiteSettings.SendMail(new MailModel() { Message = $"Merhaba {user.UserName}, </br> Hesabınızı aktifleştirmek için <a href='{SiteUrl}/Account/Activation?code={user.ActivationCode}'>Aktivasyon Kodu</a>", Subject = "Aktivasyon Kodu", To = user.Email }); return(RedirectToAction("Profile")); }
public async Task <ActionResult> AssignTech(IssueVM model) { try { var issue = _issueRepo.GetById(model.IssueId); issue.TechnicianId = model.TechnicianId; issue.IssueState = IssueStates.Atandı; issue.OptReport = model.OptReport; _issueRepo.Update(issue); var technician = await _membershipTools.NewUserStore().FindByIdAsync(issue.TechnicianId); TempData["Message"] = $"{issue.Description} adlı arızaya {technician.Name} {technician.Surname} teknisyeni atandı."; var customer = await _membershipTools.UserManager.FindByIdAsync(issue.CustomerId); var emailService = new EmailService(); var body = $"Merhaba <b>{await _membershipTools.GetNameSurname(issue.CustomerId)}</b><br>{issue.Description} adlı arızanız onaylanmıştır ve görevli teknisyen en kısa sürede yola çıkacaktır."; await emailService.SendAsync(new EmailModel() { Body = body, Subject = $"{issue.Description} adlı arıza hk." }, customer.Email); var issueLog = new IssueLog() { IssueId = issue.Id, Description = "Teknisyene atandı.", FromWhom = "Operatör" }; _issueLogRepo.Insert(issueLog); return(RedirectToAction("AllIssues", "Operator")); } catch (Exception ex) { var errorVM = new ErrorVM() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "AssignTechAsync", ControllerName = "Operator", ErrorCode = "500" }; TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM); return(RedirectToAction("Error500", "Home")); } }
public async Task <ActionResult> Activation(string code, string u) { try { if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(u)) { return(RedirectToAction("Index", "Home")); } var userStore = MembershipTools.NewUserStore(); var sonuc = userStore.Context.Set <ApplicationUser>() .FirstOrDefault(x => x.Id == u && x.ActivationCode == code); if (sonuc == null) { ViewBag.sonuc = "<span class='text-danger'>Aktivasyon işlemi başarısız</span>"; return(View()); } if (sonuc.EmailConfirmed) { ViewBag.sonuc = "<span class='text-warning'>E-posta adresiniz zaten onaylanmış.</span>"; return(View()); } sonuc.EmailConfirmed = true; await userStore.UpdateAsync(sonuc); await userStore.Context.SaveChangesAsync(); var userManager = MembershipTools.NewUserManager(); await userManager.RemoveFromRoleAsync(sonuc.Id, "Passive"); await userManager.AddToRoleAsync(sonuc.Id, "User"); ViewBag.sonuc = $"<span class='text-success'>Hoşgeldiniz {sonuc.Name} {sonuc.Surname} e-posta adresiniz başarıyla onaylanmıştır.</span>"; await SiteSettings.SendMail(new MailModel() { To = sonuc.Email, Subject = "Aktivasyon", Message = ViewBag.sonuc.ToString() }); return(View()); } catch (Exception ex) { ViewBag.sonuc = "<span class='text-danger'>Aktivasyon işlemi başarısız.</span>"; return(View()); } }
public async Task <ActionResult> Profile(ProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { var userStore = MembershipTools.NewUserStore(); var userManager = new UserManager <ApplicationUser>(userStore); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); user.Name = model.Name; user.SurName = model.Surname; user.Email = model.Email; if (userManager.FindByName(model.Username) != null && model.Username != user.UserName) { ViewBag.sonuc = "Bu kullanıcı adı zaten kullanılıyor."; return(View(model)); } user.UserName = model.Username; await userStore.UpdateAsync(user); await userStore.Context.SaveChangesAsync(); ViewBag.sonuc = "Bilgileriniz güncellenmiştir"; var model2 = new ProfileViewModel() { Email = user.Email, Name = user.Name, Surname = user.SurName, Username = user.UserName }; return(View(model2)); } catch (Exception ex) { ViewBag.sonuc = "Güncelleştirme işleminde bir hata oluştu. " + ex.Message; return(View(model)); } }