Esempio n. 1
0
        public async Task <ActionResult> Profil(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> Sisteme başarı ile kayıt oldunuz. <br/> Hesabınızı aktifleştirmek için <a href='{siteUrl}/Acount/Activation?code={user.ActivationCode}'>Aktivasyon Kodu</a>",
                    });
                }
                await userStore.UpdateAsync(user);

                await userStore.Context.SaveChangesAsync();

                var model1 = new ProfilePasswordViewModel()
                {
                    ProfileModel = new ProfilViewModel
                    {
                        Id       = user.Id,
                        Email    = user.Email,
                        Name     = user.Name,
                        Surname  = user.Surname,
                        UserName = user.UserName
                    }
                };
                ViewBag.sonuc = "Bilgileriniz Güncellendi";
                return(View(model1));
            }
            catch (Exception ex)
            {
                ViewBag.sonuc = ex.Message;
                return(View(model));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> UpdatePassword(ProfilePasswordViewModel model)
        {
            if (model.PasswordModel.NewPassword != model.PasswordModel.NewPasswordConfirm)
            {
                ModelState.AddModelError(string.Empty, "Şifreler Uyuşmuyor");
                return(View("Profil", 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, "Mevcut şifreniz doğru değil");
                    return(View("Profil", "Acount", 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("Profil"));
            }
            catch (Exception ex)
            {
                ViewBag.sonuc = "Güncelleştirme hatalı" + ex.Message;
                return(View("Profil", "Acount", model));
            }
        }
Esempio n. 3
0
        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}<br/> Aktivasyon işleminiz başarılı";

            await SiteSettings.SendMail(new MailModel()
            {
                To      = sonuc.Email,
                Message = ViewBag.sonuc.ToString(),
                Subject = "Aktivasyon",
                Bcc     = "*****@*****.**"
            });

            return(View());
        }
Esempio n. 4
0
        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 = "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 userStore.UpdateAsync(sonuc);

            await userStore.Context.SaveChangesAsync();

            await SiteSettings.SendMail(new MailModel()
            {
                To      = sonuc.Email,
                Subject = "Şifreniz Değişti",
                Message = $"Merhaba {sonuc.Name}{sonuc.Surname} <br/> Yeni Şifreniz:<b>{randompass}</b>"
            });

            ViewBag.sonuc = "E mail adresinize yeni şifreniz gönderilmiştir";
            return(View());
        }
        public async Task <ActionResult> UpdatePassword(ProfilePasswordViewModel model)
        {
            if (model.PasswordModel.YeniSifre != model.PasswordModel.SifreTekrar)
            {
                ModelState.AddModelError(string.Empty, "Şifreler uyuşmuyor");
                return(View("Profil", model));
            }
            try
            {
                var userStore   = MemberShipTools.NewUserStore();
                var userManager = new UserManager <AppUser>(userStore);
                var user        = userManager.FindById(model.ProfileModel.Id);
                user = userManager.Find(user.UserName, model.PasswordModel.EskiSifre);
                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "Mevcut şifreniz yanlış girilmiştir");
                    return(View("Profil", model));
                }
                await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.PasswordModel.YeniSifre));

                await userStore.UpdateAsync(user);

                await userStore.Context.SaveChangesAsync();

                HttpContext.GetOwinContext().Authentication.SignOut();
                return(RedirectToAction("Profil"));
            }
            catch (Exception ex)
            {
                ViewBag.sonuc = "Güncelleşme işleminde bir hata oluştu. " + ex.Message;
                return(View("Profil", model));
            }
        }
Esempio n. 6
0
        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.Email    = model.Email;
            user.Salary   = model.Salary;

            if (model.RoleId != user.Roles.ToList().First().RoleId)
            {
                var yeniRoleName = roles.First(x => x.Id == model.RoleId).Name;
                userManager.AddToRole(model.userId, yeniRoleName);
                var eskiRoleName = roles.First(x => x.Id == user.Roles.ToList().First().RoleId).Name;
                userManager.RemoveFromRole(model.userId, eskiRoleName);
            }
            //await userManager.DeleteAsync(user);//--kullanici silme
            await userStore.UpdateAsync(user);

            await userStore.Context.SaveChangesAsync();

            return(RedirectToAction("EditUser", new { id = model.userId }));
        }
        public async Task <ActionResult> UpdatePassword(ProfileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                var userStore   = MemberShipTools.NewUserStore();
                var userManager = new UserManager <ApplicationUser>(userStore);
                var user        = userManager.FindById(model.Id);
                user = userManager.Find(user.UserName, model.OldPassword);
                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "Mevcut Şifreniz yanlış girilmiştir");
                    return(View("Profil", model));
                }
                await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.NewPassword));

                await userStore.UpdateAsync(user);

                await userStore.Context.SaveChangesAsync();

                HttpContext.GetOwinContext().Authentication.SignOut();
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.sonuc = "Hata oluştu" + ex.Message;
                return(View("Profil", model));
            }
        }
        public async Task <ActionResult> Profil(ProfilePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                var userStore   = MemberShipTools.NewUserStore();
                var userManager = new UserManager <AppUser>(userStore);
                var user        = userManager.FindById(model.ProfileModel.Id);
                user.Ad    = model.ProfileModel.Ad;
                user.Soyad = model.ProfileModel.Soyad;
                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 MailViewModel
                    {
                        Kime  = user.Email,
                        Konu  = "Personel Yönetimi - Aktivasyon",
                        Mesaj =
                            $"Merhaba {user.Ad} {user.Soyad} <br/>Email adresinizi <b>değiştirdiğiniz</b> için hesabınızı tekrar aktif etmelisiniz. <a href='{siteUrl}/Hesap/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,
                        Ad          = user.Ad,
                        Soyad       = user.Soyad,
                        KullaniciAd = user.UserName
                    }
                };
                ViewBag.sonuc = "Bilgileriniz güncelleşmiştir";
                return(View(model1));
            }
            catch (Exception ex)
            {
                ViewBag.sonuc = ex.Message;
                return(View(model));
            }
        }
        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.ProfileViewModel.Id);
                user.Name    = model.ProfileViewModel.Name;
                user.Surname = model.ProfileViewModel.Surname;
                if (user.Email != model.ProfileViewModel.Email)
                {
                    user.Email = model.ProfileViewModel.Email;//aktivasyon gerekli
                    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 MailViewModel
                    {
                        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 İçin Tıklayınız.</a>"
                    });

                    HttpContext.GetOwinContext().Authentication.SignOut();
                }
                await userStore.UpdateAsync(user);

                await userStore.Context.SaveChangesAsync();

                var model1 = new ProfilePasswordViewModel()
                {
                    ProfileViewModel = new ProfileViewModel
                    {
                        Id       = user.Id,
                        Email    = user.Email,
                        Surname  = user.Surname,
                        Name     = user.Name,
                        Username = user.UserName
                    }
                };
                ViewBag.sonuc = "<b>Bilgileriniz Güncellenmiştir.</b>";
                return(View(model1));
            }
            catch (Exception ex)
            {
                ViewBag.sonuc = ex.Message;
                return(View(model));
            }
        }
Esempio n. 10
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Mevcut şifre yanlış...");
                return(RedirectToAction("MyProfile"));
            }

            var userStore   = MemberShipTools.NewUserStore();
            var userManager = new UserManager <ApplicationUser>(userStore);

            var userName = userManager.FindById(HttpContext.User.Identity.GetUserId()).UserName;

            var user = userManager.Find(userName, model.OldPassword);

            if (user == null)
            {
                ModelState.AddModelError(string.Empty, "Mevcut şifre yanlış...");
                return(RedirectToAction("MyProfile"));
            }

            //yeni passwordu sifrele ve güncelle:
            await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(model.Password));

            await userStore.UpdateAsync(user);

            await userStore.Context.SaveChangesAsync();

            return(RedirectToAction("Logout"));
        }
Esempio n. 11
0
        protected List <SelectListItem> GetUserList()
        {
            var data = new List <SelectListItem>();

            MemberShipTools.NewUserStore().Users
            .ToList()
            .ForEach(x =>
            {
                data.Add(new SelectListItem()
                {
                    Text  = $"{x.Ad} {x.Soyad}",
                    Value = x.Id
                });
            });
            return(data);
        }
        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());

            user.Email   = model.Email;
            user.Name    = model.Name;
            user.Surname = model.Surname;



            await userStore.UpdateAsync(user);

            await userStore.Context.SaveChangesAsync();

            return(RedirectToAction("Profile"));
        }
Esempio n. 13
0
        public async Task <ActionResult> EditProfile(ProfileEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("MyProfile", model));
            }

            var userStore   = MemberShipTools.NewUserStore();
            var userManager = new UserManager <ApplicationUser>(userStore);
            var user        = userManager.FindByName(model.UserName);

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase fu = Request.Files[0];

                string resimYolu = fu.FileName;

                string uzanti = Path.GetExtension(resimYolu); //.jpg

                if (fu != null && fu.ContentType.Contains("image") && fu.ContentLength < 1000000)
                {
                    System.IO.File.Delete(Server.MapPath(user.AvatarPath));
                    //yeni resim yolunu olustur:
                    resimYolu = "/images/Users/" + model.UserName + uzanti;
                    fu.SaveAs(Server.MapPath(resimYolu));
                    user.AvatarPath = resimYolu;
                    user.Name       = model.Name;
                    user.Surname    = model.Surname;
                    user.Email      = model.Email;
                    await userStore.UpdateAsync(user);

                    await userStore.Context.SaveChangesAsync();
                }
            }

            return(RedirectToAction("MyProfile"));
        }