public ActionResult IlanListele() { var userManager = MembershipTools.NewUserManager(); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); List <KonutViewModel> model = new KonutRepo().GetAll().Where(x => x.KullaniciID == user.Id).Select(x => new KonutViewModel() { Aciklama = x.Aciklama, YayindaMi = x.YayindaMi, Adres = x.Adres, Baslik = x.Baslik, BinaYasi = x.BinaYasi, Boylam = x.Boylam, EklenmeTarihi = x.EklenmeTarihi, Enlem = x.Enlem, Fiyat = x.Fiyat, FotografYollari = (x.Fotograflar.Count > 0 ? x.Fotograflar.Select(y => y.Yol).ToList() : new List <string>()), ID = x.ID, IlanTuruID = x.IlanTuruID, IsitmaTuruID = x.IsitmaSistemiID, KatTuruID = x.KatturID, KullaniciID = x.KullaniciID, Metrekare = x.Metrekare, OdaSayisi = x.OdaSayisi, OnaylanmaTarihi = x.OnaylanmaTarihi }).ToList(); return(View(model)); }
public ActionResult ArizaEkle() { var userManager = MembershipTools.NewUserManager(); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); if (userManager.IsInRole(user.Id, "Passive") || userManager.IsInRole(user.Id, "Banned")) { ModelState.AddModelError(string.Empty, "Profiliniz Yeni ilan açmak için uygun değildir."); return(RedirectToAction("Profile", "Account")); } var model = new ArizaViewModel(); var markalar = new List <SelectListItem>(); new PcMarkaRepo().GetAll().OrderBy(x => x.MarkaAdi).ToList().ForEach(x => markalar.Add(new SelectListItem() { Text = x.MarkaAdi, Value = x.ID.ToString() })); var modeller = new List <SelectListItem>(); new PcModelRepo().GetAll().OrderBy(x => x.ModelAdi).ToList().ForEach(x => modeller.Add(new SelectListItem() { Text = x.ModelAdi, Value = x.ID.ToString() })); ViewBag.modelleri = modeller; ViewBag.markalari = markalar; return(View(model)); }
public async Task <ActionResult> Login(LoginViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var user = await userManager.FindAsync(model.UserName, model.Password); if (user == null) { ModelState.AddModelError(string.Empty, "Böyle bir kullanıcı bulunmamaktadır!"); return(View(model)); } var authManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authManager.SignIn(new AuthenticationProperties { IsPersistent = true }, userIdentity); return(RedirectToAction("Index", "Home")); }
public List <UserViewModel> GetAllUsers() { var UserList = new List <UserViewModel>(); var userManager = MembershipTools.NewUserManager(); List <ApplicationUser> list = userManager.Users.ToList(); foreach (var item in list) { UserList.Add(new UserViewModel() { Name = item.Name, SurName = item.SurName, Email = item.Email, UserName = item.UserName, ID = item.Id, RoleID = item.Roles.First()?.RoleId, EmailConfirmed = item.EmailConfirmed, PhoneNumber = item.PhoneNumber, RegisterDate = item.RegisterDate, RoleName = MembershipTools.GetRoleName(item.Roles.First()?.RoleId) }); } return(UserList); }
public ActionResult UserProfile() { try { var id = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(); var user = MembershipTools.NewUserManager().FindById(id); var data = new ProfilePasswordViewModel() { UserProfileViewModel = new UserProfileViewModel() { Email = user.Email, Id = user.Id, Name = user.Name, PhoneNumber = user.PhoneNumber, Surname = user.Surname, UserName = user.UserName, AvatarPath = string.IsNullOrEmpty(user.AvatarPath) ? "/assets/img/avatars/avatar3.jpg" : user.AvatarPath } }; return(View(data)); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "UserProfile", ControllerName = "Account", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }
public ActionResult ArizaYonetimi() { var userManager = MembershipTools.NewUserManager(); var id = HttpContext.User.Identity.GetUserId(); var user = userManager.FindById(id); List <ArizaViewModel> arizalar = new ArizaRepo().GetAll().Where(z => z.TeknikerID == user.Id).OrderByDescending(y => y.EklemeTarihi).Select(x => new ArizaViewModel() { KullaniciID = x.KullaniciID, Aciklama = x.Aciklama, Adres = x.Adres, Baslik = x.Baslik, Boylam = x.Boylam, Enlem = x.Enlem, MarkaID = x.MarkaID, ModelID = x.ModelID, TeknikerID = x.TeknikerID, FotografYollari = (x.Fotograflari.Count > 0 ? x.Fotograflari.Select(y => y.Yol).ToList() : new List <string>()), ID = x.ID, OnaylamaTarihi = x.OnaylamaTarihi, OnaylandiMi = x.OnaylandiMi, ArizaYapildiMi = x.ArizaYapildiMi, EklemeTarihi = x.EklemeTarihi }).ToList(); return(View(arizalar)); }
public async Task <ActionResult> ChangePassword(ProfilePasswordViewModel model) { try { var userManager = MembershipTools.NewUserManager(); var id = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(); var user = MembershipTools.NewUserManager().FindById(id); var data = new ProfilePasswordViewModel() { UserProfileViewModel = new UserProfileViewModel() { Email = user.Email, Id = user.Id, Name = user.Name, PhoneNumber = user.PhoneNumber, Surname = user.Surname, UserName = user.UserName } }; model.UserProfileViewModel = data.UserProfileViewModel; if (!ModelState.IsValid) { model.ChangePasswordViewModel = new ChangePasswordViewModel(); return(View("UserProfile", model)); } var result = await userManager.ChangePasswordAsync( HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(), model.ChangePasswordViewModel.OldPassword, model.ChangePasswordViewModel.NewPassword); if (result.Succeeded) { //todo kullanıcıyı bilgilendiren bir mail atılır return(RedirectToAction("Logout", "Account")); } else { var err = ""; foreach (var resultError in result.Errors) { err += resultError + " "; } ModelState.AddModelError("", err); model.ChangePasswordViewModel = new ChangePasswordViewModel(); return(View("UserProfile", model)); } } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "UserProfile", ControllerName = "Account", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }
public ActionResult KullaniciDuzenle(KullaniciDuzenleViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var userManager = MembershipTools.NewUserManager(); var seciliUser = userManager.Users.Where(x => x.Id == model.ID).FirstOrDefault(); // var checkUser = userManager.FindByName(model.Username); //if (checkUser!=null) //{ // ModelState.AddModelError(string.Empty, "Bu kullanıcı adı daha önceden kayıt edilmiş!"); // return RedirectToAction("KullaniciDuzenle",new { id=model.ID}); //} var eskirol = MembershipTools.NewRoleManager().FindById(seciliUser.Roles.FirstOrDefault().RoleId).Name; var yenirol = MembershipTools.NewRoleManager().FindById(model.RoleID).Name; userManager.RemoveFromRole(model.ID, eskirol); //eskirol silindi userManager.AddToRole(model.ID, yenirol); // rol eklendi //if (model.Password!=null) //{ // userManager.RemovePassword(model.ID); // userManager.AddPassword(model.ID, model.Password); //} seciliUser.Name = model.Name; seciliUser.SurName = model.Surname; seciliUser.UserName = model.Username; seciliUser.PhoneNumber = model.Telefon; seciliUser.FirmaAdi = model.FirmaAdi; seciliUser.Email = model.Email; userManager.Update(seciliUser); return(RedirectToAction("KullaniciListele", "Admin")); }
public ActionResult AnketDetay(int?id) { if (id == null) { return(RedirectToAction("AnketYonetimi")); } var anket = new AnketRepo().GetByID(id.Value); if (anket == null) { return(RedirectToAction("AnketYonetimi")); } var userManager = MembershipTools.NewUserManager(); var Kullanici = userManager.FindById(anket.KullaniciID); var Teknisyen = userManager.FindById(anket.TeknikerID); var model = new AnketViewModel() { ID = anket.ID, Aciklama = anket.Aciklama, ArizaID = anket.ArizaID, KullaniciID = Kullanici.Name, Puan = anket.Puan, TeknikerID = Teknisyen.Name }; return(View(model)); }
public JsonResult AdimDataKaydet(Guid id, string sonucData) { var isAtamaRepo = new IsAtamaRepo(); var baglayiciRepo = new BaglayiciRepo(); var isAtama = isAtamaRepo.Queryable().First(x => x.Id == id); var baglayici = baglayiciRepo.Queryable().FirstOrDefault(x => x.SemaId == isAtama.SemaId && x.Id == isAtama.SonAdimId); if (baglayici == null) { isAtama.TamamlandiMi = true; if (isAtamaRepo.Update() > 0) { var hubContext = GlobalHost.ConnectionManager.GetHubContext <WorkflowHub>(); var user = MembershipTools.NewUserManager().FindById(isAtama.AtananKullaniciId); hubContext.Clients.User(user.UserName).endCurrentTask(); return(Json(true)); } else { return(Json(false)); } } isAtama.SonAdimId = baglayici.Id2; isAtama.SonucDataJson = sonucData; var result = isAtamaRepo.Update() > 0; return(Json(result)); }
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> Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var checkUser = userManager.FindByName(model.Username); if (checkUser != null) { ModelState.AddModelError(string.Empty, "Bu kullanıcı adı daha önceden kayıt edilmiş"); return(View(model)); } var activationCode = Guid.NewGuid().ToString().Replace("-", ""); var user = new ApplicationUser() { Name = model.Name, SurName = model.Surname, Email = model.Email, FirmaAdi = model.FirmaAdi, PhoneNumber = model.Telefon, UserName = model.Username, ActivationCode = activationCode }; var sonuc = userManager.Create(user, model.Password); if (sonuc.Succeeded) { if (userManager.Users.Count() == 1) { userManager.AddToRole(user.Id, IdentityRoles.Admin.ToString()); } else { userManager.AddToRole(user.Id, IdentityRoles.Passive.ToString()); } 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 = "KLY Teknik Servis - Üyelik Aktivasyon", Message = $"Merhaba {user.Name} {user.SurName} <br/>Hesabınızı aktifleştirmek için <b><a href='{siteUrl}/Account/Activation?code={activationCode}'>Aktivasyon Kodu</a></b> tıklayınız.\nKullanıcı Adınız : <b>{user.UserName}</b>" }); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "Kullanıcı kayıt işleminde hata oluştu!"); return(View(model)); } }
public async Task <ActionResult> Register(LoginAndRegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var checkUser = userManager.FindByName(model.Register.Name); if (checkUser != null) { ModelState.AddModelError(string.Empty, "Bu kullanıcı zaten kayıtlı!"); return(View(model)); } var aktivasyonKodu = Guid.NewGuid().ToString().Replace("-", ""); var user = new ApplicationUser() { Name = model.Register.Name, Surname = model.Register.Surname, Email = model.Register.Email, UserName = model.Register.Username, ActivationCode = aktivasyonKodu }; var sonuc = userManager.Create(user, model.Register.Password); if (sonuc.Succeeded) { if (userManager.Users.ToList().Count == 1) { userManager.AddToRole(user.Id, "Admin"); await SiteSettings.SendMail(new MailModel() { Message = $"Merhaba {user.UserName}, </br> Sisteme Admin rolünde kayıt oldunuz. <br/><a href='http://localhost:28442/Account/Profile'>Profil Sayfanız</a>", Subject = "Hoşgeldiniz", To = user.Email }); } else { //userManager.AddToRole(user.Id, "User"); userManager.AddToRole(user.Id, "Passive"); await SiteSettings.SendMail(new MailModel() { Message = $"Merhaba {user.UserName}, </br> Sisteme başarı ile kayıt oldunuz. <br/> Hesabınızı aktifleştirmek için <a href='http://localhost:28442/Account/Activation?code={aktivasyonKodu}'>Aktivasyon Kodu</a>", Subject = "Hoşgeldiniz", To = user.Email }); } return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "Kullanıcı kayıt işleminde hata oluştu!"); return(View(model)); } }
public ActionResult KullaniciEkle(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var checkUser = userManager.FindByName(model.Ad); if (checkUser != null) { ModelState.AddModelError(string.Empty, "Bu kullanıcı adı daha önceden kayıt edilmiş"); return(View(model)); } var activationCode = Guid.NewGuid().ToString().Replace("-", ""); var user = new ApplicationUser() { Ad = model.Ad, Soyad = model.Soyad, Email = model.Email, UserName = model.KullaniciAdi, PasswordHash = model.Sifre, AktivasyonKodu = activationCode, EmailConfirmed = true, }; var sonuc = userManager.Create(user, model.Sifre); if (sonuc.Succeeded) { userManager.AddToRole(user.Id, model.RolAdi.ToString()); if (model.RolAdi == TeknikServis.Entity.Enums.IdentityRoles.Teknisyen) { List <TeknisyenViewModel> teknisyenModel = new List <TeknisyenViewModel>(); new TeknisyenRepo().Insert(new Teknisyen() { UyeId = user.Id, BostaMi = true, }); } string siteUrl = Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); return(RedirectToAction("KullanicilariListele", "Admin")); } else { ModelState.AddModelError(string.Empty, "Kullanıcı kayıt işleminde hata oluştu!"); return(View(model)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var checkUser = userManager.FindByName(model.UserName); if (checkUser != null) { ModelState.AddModelError("", "Bu kullanıcı adı zaten alınmış."); return(View(model)); } checkUser = userManager.FindByEmail(model.Email); if (checkUser != null) { ModelState.AddModelError("", "Bu e-mail zaten alınmış."); return(View(model)); } var activationCode = Guid.NewGuid().ToString().Replace("-", ""); var user = new ApplicationUser() { Email = model.Email, UserName = model.UserName, Name = model.Name, Surname = model.Surname, ActivationCode = activationCode, PhotoURL = "/images/user.png" }; var result = userManager.Create(user, model.Password); if (result.Succeeded) { userManager.AddToRole(user.Id, userManager.Users.Count() == 1 ? "Admin" : "Passive"); var siteUrl = Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); if (userManager.Users.Count() > 1) { await SiteSettings.SendMail(new MailModel() { To = user.Email, Subject = "Murat Bircan Blog - Aktivasyon", Message = $"Merhaba {user.Name} {user.Surname}</br> Hesabınızı aktifleştirmek için <b><a href='{siteUrl}/Account/Activation?code={activationCode}&u={user.Id}'>buraya</a></b> tıklayınız." }); } return(RedirectToAction("Login", "Account")); } ModelState.AddModelError("", "Kayıt işleminde bir hata oluştu."); return(View(model)); }
public async Task <ActionResult> ArizaDuzenle(ArizaViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("ArizaYonetimi")); } var ariza = new ArizaRepo().GetByID(model.ID); ariza.Aciklama = model.Aciklama; ariza.Adres = model.Adres; ariza.Baslik = model.Baslik; ariza.Boylam = model.Boylam; ariza.Enlem = model.Enlem; ariza.MarkaID = model.MarkaID; ariza.ModelID = model.ModelID; ariza.TeknikerID = model.TeknikerID; if (ariza.TeknikerID != null) { #region Kullanıcı Bilgilendirme var userManager = MembershipTools.NewUserManager(); var Teknisyen = userManager.FindById(ariza.TeknikerID); string SiteUrl = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); if (ariza.OnaylandiMi == true && model.OnaylandiMi == false) { await SiteSettings.SendMail(new MailModel() { Message = $"Merhaba {Teknisyen.Name}<br/><strong>'{ariza.ID}'</strong> nolu Arıza sistemden kaldırılmıştır. Yapacağınız işlemleri durdurmanız rica olunur.<br/>", Subject = "Arıza Sistemden kaldırıldı", To = Teknisyen.Email }); } else if (ariza.OnaylandiMi == false && model.OnaylandiMi == true) { ariza.OnaylamaTarihi = DateTime.Now; await SiteSettings.SendMail(new MailModel() { Message = $"Merhaba {Teknisyen.Name}<br/><strong>'{ariza.ID}'</strong> nolu arıza sisteme alınmıştır<br/><a href='{SiteUrl}/Teknisyen/ArizaDetay/{ariza.ID}'>Arızayı görmek için tıklayınız</a>", Subject = "Arızanız sisteme alındı!", To = Teknisyen.Email }); } #endregion } ariza.OnaylandiMi = model.OnaylandiMi; new ArizaRepo().Update(); return(RedirectToAction("ArizaDetay", new { id = ariza.ID })); }
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 List <SelectListItem> TeknisyenSelectList() { var teknisyenList = MembershipTools.NewUserManager().Users.Where(x => x.Roles.FirstOrDefault().RoleId == "2628da05-6a23-48dc-90bb-8db46f818762").ToList(); var teknisyenler = new List <SelectListItem>(); teknisyenList.ForEach(x => teknisyenler.Add(new SelectListItem {//burda problem var ! Text = x.Name + " " + x.SurName, Value = x.Id.ToString() })); return(teknisyenler); }
public ActionResult Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var checkUser = userManager.FindByName(model.Name); if (checkUser != null) { ModelState.AddModelError(string.Empty, "Bu kullanıcı zaten kayıtlı!"); return(View(model)); } var user = new ApplicationUser() { Name = model.Name, Surname = model.Surname, Email = model.Email, UserName = model.Username, }; var sonuc = userManager.Create(user, model.Password); if (sonuc.Succeeded) { if (userManager.Users.ToList().Count == 1) { userManager.AddToRole(user.Id, "Admin"); } else if (userManager.Users.ToList().Count == 2) { userManager.AddToRole(user.Id, "Operator"); } else if (userManager.Users.ToList().Count == 3) { userManager.AddToRole(user.Id, "Teknisyen"); } else { userManager.AddToRole(user.Id, "User"); } return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "Kullanıcı kayıt işleminde hata oluştu!"); return(View(model)); } }
public async Task <ActionResult> RecoverPassword(RecoverPasswordViewModel model) { try { var userStore = MembershipTools.NewUserStore(); var userManager = MembershipTools.NewUserManager(); 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); await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(newPassword)); var result = userStore.Context.SaveChanges(); if (result == 0) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu", ActionName = "RecoverPassword", ControllerName = "Account", ErrorCode = 500 }; return(RedirectToAction("Error", "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 sistemize giriş yapabilirsiniz.</p>"; emailService.Send(new IdentityMessage() { Body = body, Subject = $"{user.UserName} Şifre Kurtarma" }, user.Email); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "RecoverPassword", ControllerName = "Account", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } return(View()); }
public ActionResult Profile() { var userManager = MembershipTools.NewUserManager(); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); var model = new ProfileViewModel() { Email = user.Email, Ad = user.Ad, Soyad = user.Soyad, KullaniciAdi = user.UserName }; return(View(model)); }
[Authorize] // sadece giriş yapılmışlar erişebilecek demektir. public ActionResult Profile() { var userManager = MembershipTools.NewUserManager(); var user = userManager.FindById(HttpContext.User.Identity.GetUserId()); var model = new ProfileViewModel() { Email = user.Email, Name = user.Name, Surname = user.Surname, Username = user.UserName }; return(View(model)); }
public ActionResult Settings() { var userManager = MembershipTools.NewUserManager(); List <ApplicationUser> kullanicilar = userManager.Users.ToList(); var model = new SettingsViewModel() { PcMarkalari = new PcMarkaRepo().GetAll().Select(x => new PcMarkaViewModel() { ID = x.ID, MarkaAdi = x.MarkaAdi }).ToList(), PcModelleri = new PcModelRepo().GetAll().Select(x => new PcModelViewModel() { ID = x.ID, MarkaId = x.MarkaID, ModelAdi = x.ModelAdi }).ToList(), Kullanicilar = kullanicilar.Select(x => new KullaniciViewModel() { ID = x.Id, Email = x.Email, KullaniciAdi = x.UserName, Rol = MembershipTools.NewRoleManager().FindById(x.Roles.FirstOrDefault().RoleId).Name }).ToList(), Yetkiler = MembershipTools.NewRoleManager().Roles.ToList().Select(x => new YönetimYetkiViewModel() { Yetki = x.Name }).ToList() }; var roller = new List <SelectListItem>(); MembershipTools.NewRoleManager().Roles.ToList().ForEach(r => roller.Add(new SelectListItem() { Text = r.Name, Value = r.Id })); ViewBag.roller = roller; var markalar = new List <SelectListItem>(); new PcMarkaRepo().GetAll().ForEach(m => markalar.Add(new SelectListItem() { Text = m.MarkaAdi, Value = m.ID.ToString() })); ViewBag.markalar = markalar; return(View(model)); }
public IHttpActionResult GetLoginInfo() { var userManager = MembershipTools.NewUserManager(); var user = userManager.FindById(HttpContext.Current.User.Identity.GetUserId()); return(Ok(new UserProfileViewModel() { Name = user.Name, UserName = user.UserName, Email = user.Email, AvatarPath = user.AvatarPath, Surname = user.Surname, Id = user.Id })); }
public object GetLoginData() { var user = MembershipTools.NewUserManager().FindById(HttpContext.Current.User.Identity.GetUserId()); var rol = MembershipTools.NewRoleManager().FindById(user.Roles.First().RoleId).Name; return(new { Id = user.Id, UserName = user.UserName, Name = user.Name, Surname = user.Surname, Email = user.Email, Rol = rol }); }
public ActionResult Detay(int id) { var kullaniciId = new ArizaRepo().GetById(id).UserID; var teknisyenler = TeknisyenSelectList(); ViewBag.Teknisyenler = teknisyenler; var model = new ArizaDetayViewModel { Ariza = new ArizaRepo().GetById((int)id), DurumListesi = new ArizaDurumRepo().GetAll().Where(x => x.ArizaID == id).ToList(), User = MembershipTools.NewUserManager().Users.FirstOrDefault(x => x.Id == kullaniciId) }; return(View(model)); }
public async Task <ActionResult> Login(LoginViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var userManager = MembershipTools.NewUserManager(); var roleManager = MembershipTools.NewRoleManager(); var user = await userManager.FindAsync(model.Username, model.Password); if (user == null) { ModelState.AddModelError(string.Empty, "Böyle bir kullanıcı bulunamadı"); return(View(model)); } if (user.Roles.First().RoleId == roleManager.FindByName("Passive").Id) { ModelState.AddModelError(string.Empty, "Lütfen Email aktivasyonunuzu yapınız."); return(View(model)); } var authManager = HttpContext.GetOwinContext().Authentication; var userIdentity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authManager.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe }, userIdentity); if (string.IsNullOrEmpty(model.ReturnUrl)) { return(RedirectToAction("Index", "Home")); } try { var url = model.ReturnUrl.Split('/'); if (url.Length == 4) { return(RedirectToAction(url[2], url[1], new { id = url[3] })); } else { return(RedirectToAction(url[2], url[1])); } } catch { return(RedirectToAction("Index", "Home")); } }
public async Task <ActionResult> ArizaAnket(int?id, AnketViewModel model) { if (id == null) { return(RedirectToAction("Index", "Home")); } var ariza = new ArizaRepo().GetByID(id.Value); if (ariza == null) { return(RedirectToAction("Index", "Home")); } Anket yeniAnket = new Anket() { Aciklama = model.Aciklama, ArizaID = ariza.ID, KullaniciID = ariza.KullaniciID, Puan = model.Puan, TeknikerID = ariza.TeknikerID }; new AnketRepo().Insert(yeniAnket); string SiteUrl = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port); var roleManager = MembershipTools.NewRoleManager(); var users = roleManager.FindByName("Admin").Users; var userManager = MembershipTools.NewUserManager(); List <string> mailler = new List <string>(); foreach (var item in users) { mailler.Add(userManager.FindById(item.UserId).Email); } foreach (var mail in mailler) { await SiteSettings.SendMail(new MailModel { Subject = "Yeni Anket Bildirimi", Message = $"Sayın Operatör,<br/>Sitenize bir anket eklendi, Lütfen gereken işlemleri gerçekleştirin.<br/><a href='{SiteUrl}/Admin/AnketDetay/{yeniAnket.ID}'>Şimdi Bak</a><p>İyi Çalışmalar<br/>Sitenin Nöbetçisi</p>", To = mail }); } return(RedirectToAction("Index", "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 override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); var userManager = MembershipTools.NewUserManager(); var user = userManager.Find(context.UserName, context.Password); if (user == null) { context.SetError("Geçersiz istek", "Hatalı kullanıcı bilgisi"); } else { ClaimsIdentity identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ExternalBearer); context.Validated(identity); } }