public async Task <ActionResult> UserProfile()
        {
            var id = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();

            try
            {
                var userManager = NewUserManager();
                var user        = await userManager.FindByIdAsync(id);

                var data = new ProfilePasswordViewModel()
                {
                    UserProfileViewModel = new UserProfileViewModel()
                    {
                        Email       = user.Email,
                        Id          = user.Id,
                        Name        = user.Name,
                        Surname     = user.Surname,
                        PhoneNumber = user.PhoneNumber,
                        UserName    = user.UserName
                    }
                };
                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 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));
            }
        }
Пример #3
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));
            }
        }
Пример #4
0
        // UserProfile viewden guncelleye tıkladığımıza bize oradan ProfilePasswordViewModel tipinde bir model gelecek onu parametre olarak alacagız.
        public async Task <ActionResult> UpdateProfile(ProfilePasswordViewModel model)
        {
            if (!ModelState.IsValid) // Modelimiz gecerli değilse UserProfile sayfasına geri donecegiz.
            {
                return(View("UserProfile", model));
            }
            try
            {
                // Kullanıcıya ihtiyacımız var onu bulmak içinde usermanegerı kullanıyoruz.
                var userManager = NewUserManager();
                var user        = await userManager.FindByIdAsync(model
                                                                  .UserProfileViewModel.Id); // User ı bulduk ve aşağıda gelen modele göre userımıza gerekli atamaları yaptık.

                user.Name        = model.UserProfileViewModel.Name;
                user.Surname     = model.UserProfileViewModel.Surname;
                user.PhoneNumber = model.UserProfileViewModel.PhoneNumber;
                // Mailde değişiklik yaptığımızda yeni maile aktivasyon kodu göndermek ve role de değişiklik yapmak için  bu if i yazdık.
                if (user.Email != model.UserProfileViewModel.Email)
                {
                    // todo tekrar aktıvasyon maili gonderilmeli rolu de aktif olmamış role cevrilmeli
                }
                user.Email = model.UserProfileViewModel.Email;

                await userManager.UpdateAsync(user);

                TempData["Message"] = "Guncelleme şlemi başarılı";
                return(RedirectToAction("UserProfile"));
            }
            catch (Exception)
            {
                // todo hata mesajlarını al
                throw;
            }
        }
Пример #5
0
        public async Task <IActionResult> Password(ProfilePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(User.Identity.Name);

                var check = await UserManager.CheckPasswordAsync(user, model.Password);

                if (!check)
                {
                    ModelState.AddModelError("Password", "La contraseña es incorrecta");
                }
                else
                {
                    var result = await UserManager.ChangePasswordAsync(user, model.Password, model.NewPassword);

                    if (result.Succeeded)
                    {
                        this.ShowSuccess("La contraseña se ha cambiado correctamente");
                        return(this.RedirectAjax(Url.Action("Index", "Requisiciones")));
                    }
                    else
                    {
                        var erroMessage = "";
                        foreach (var item in result.Errors)
                        {
                            erroMessage += item.Description + "/n";
                        }
                        ModelState.AddModelError("NewPassword", erroMessage);
                    }
                }
            }

            return(PartialView("_PasswordPartial", model));
        }
Пример #6
0
        public async Task <ActionResult> ChangePassword(ProfilePasswordViewModel model)
        {
            try
            {
                var userManager = NewUserManager();
                var id          = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
                var user        = 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"));
            }
        }
Пример #7
0
        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));
            }
        }
Пример #8
0
        public async Task <IActionResult> Index()
        {
            ApplicationUser user = await _membershipTools.UserManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var data = new ProfilePasswordViewModel()
            {
                UserProfileViewModel = new UserProfileViewModel()
                {
                    Email            = user.Email,
                    Id               = user.Id,
                    Name             = user.Name,
                    PhoneNumber      = user.Phone,
                    Surname          = user.Surname,
                    UserName         = user.UserName,
                    TechnicianStatus = user.TechnicianStatus,
                    AvatarPath       = string.IsNullOrEmpty(user.AvatarPath) ? "/assets/img/user.png" : user.AvatarPath,
                    Latitude         = user.Latitude,
                    Longitude        = user.Longitude
                }
            };

            return(View("UserProfile", data));
        }
Пример #9
0
 public ActionResult UserProfile()
 {
     try
     {
         var id   = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
         var user = NewUserManager().FindById(id);
         var data = new ProfilePasswordViewModel()
         {
             UserProfileViewModel = new UserProfileViewModel()
             {
                 Email      = user.Email,
                 Id         = user.Id,
                 Ad         = user.Ad,
                 TelefonNO  = user.PhoneNumber,
                 Soyad      = user.Soyad,
                 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           = $"Giriş Sırasında Bir Hata Oluştu",
             ActionName     = "Index",
             ControllerName = "Account",
             ErrorCode      = 404
         };
         return(RedirectToAction("Error", "Home"));
     }
 }
Пример #10
0
        public async Task <ActionResult> ChangePassword(ProfilePasswordViewModel model)
        {
            try
            {
                //ApplicationUser user = await _membershipTools.UserManager.GetUserAsync(HttpContext.User);

                var name = _membershipTools.IHttpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
                var user = await _membershipTools.UserManager.FindByNameAsync(name);

                ChangePasswordViewModel data = new ChangePasswordViewModel()
                {
                    OldPassword        = model.ChangePasswordViewModel.OldPassword,
                    NewPassword        = model.ChangePasswordViewModel.NewPassword,
                    ConfirmNewPassword = model.ChangePasswordViewModel.ConfirmNewPassword
                };

                model.ChangePasswordViewModel = data;
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                IdentityResult result = await _membershipTools.UserManager.ChangePasswordAsync(await _membershipTools.UserManager.GetUserAsync(HttpContext.User),
                                                                                               model.ChangePasswordViewModel.OldPassword, model.ChangePasswordViewModel.NewPassword);

                if (result.Succeeded)
                {
                    EmailService emailService = new EmailService();
                    string       body         = $"Merhaba <b>{user.Name} {user.Surname}</b><br>Hesabınızın şifresi değiştirilmiştir. <br> Bilginiz dahilinde olmayan değişiklikler için hesabınızı güvence altına almanızı öneririz.</p>";
                    emailService.Send(new HelpDesk.Models.Models.EmailModel()
                    {
                        Body = body, Subject = "Şifre Değiştirme hk."
                    }, user.Email);

                    return(RedirectToAction("Logout", "Account"));
                }
                else
                {
                    string err = "";
                    foreach (IdentityError resultError in result.Errors)
                    {
                        err += resultError + " ";
                    }
                    ModelState.AddModelError("", err);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "ChangePassword",
                    ControllerName = "Account",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #11
0
 public ActionResult UserProfile()
 {
     try
     {
         var id   = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
         var user = 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"));
     }
 }
Пример #12
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));
            }
        }
Пример #13
0
 // Profil işlemleri
 public ActionResult UserProfile()
 {
     // Profile linkine tıkladığımızda sayfada profil bilgilerimizi gormemiz gerekir onun için burada doldurma işlemi yapıyoruz.
     try
     {
         var id   = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(); // Baglı olan kullanıcının id sini dondurecek.
         var user = NewUserManager().FindById(id);                                         // Bu id deki kullanıcıyı bulduk.
         // Kullanıcıyı bulduktan sonra returnda kullanacagımız modeli tanımlamamız gerekecek.
         // Object initialize ile doldurma işlemi yaptık.
         var data = new ProfilePasswordViewModel()
         {
             UserProfileViewModel = new UserProfileViewModel()
             {
                 Email       = user.Email,
                 Id          = user.Id,
                 Name        = user.Name,
                 Surname     = user.Surname,
                 PhoneNumber = user.PhoneNumber,
                 UserName    = user.UserName
             }
         };
         return(View(data));  // Datayı doldurduktan sonra view e gonderiyoruz. Böylece bilgilerimizin dolu gelmesini saglamış olduk.
     }
     catch (Exception)
     {
         throw;
     }
     return(View());
 }
Пример #14
0
        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));
            }
        }
Пример #15
0
        // UserProfile viewden şifre guncelleye tıkladığımıza bize oradan ProfilePasswordViewModel tipinde bir model gelecek onu parametre olarak alacagız.
        public async Task <ActionResult> ChangePassword(ProfilePasswordViewModel model)
        {
            try
            {
                // user ile ilgili işlemlerimiz oldugu için usermanager kullandık.
                // Model boş gelmesin diye burada modeli dolduruyoruz.
                var userManager = NewUserManager();
                var id          = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
                var user        = 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;            // Datayı modele eşitliyoruz böylece modelimiz artık giriş yapmış kişinin bilgilerini taşıyor.
                if (!ModelState.IsValid)                                           // Modelimiz gecerli değilse UserProfile sayfasına geri donecegiz.
                {
                    model.ChangePasswordViewModel = new ChangePasswordViewModel(); // Password alanının temizlenmesi için
                    return(View("UserProfile", model));
                }


                var result = await userManager.ChangePasswordAsync(
                    HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(),
                    model.ChangePasswordViewModel.OldPassword, model.ChangePasswordViewModel.NewPassword); // Giriş yapmış kullanıcının id sini getirdik ve usermangerdaki changepassword metodunu kullandık.

                if (result.Succeeded)                                                                      // Eger başarılı bir guncelleme yapıldıysa
                {
                    //todo kullanıcıyı bilgilendiren bir mail atılır
                    return(RedirectToAction("Logout", "Account"));
                }
                else // Hata varsa
                {
                    var err = "";
                    foreach (var resultError in result.Errors)
                    {
                        err += resultError + " ";
                    }
                    ModelState.AddModelError("", err);
                    model.ChangePasswordViewModel = new ChangePasswordViewModel();
                    return(View("UserProfile", model));
                }
            }
            catch (Exception)
            {
                // todo hata mesajlarını ekle
                throw;
            }
        }
Пример #16
0
        public async Task <IActionResult> Password()
        {
            var user = await UserManager.FindByEmailAsync(User.Identity.Name);

            var model = new ProfilePasswordViewModel
            {
                UsuCorreo = user.UsuCorreo
            };


            return(PartialView("_PasswordPartial", model));
        }
Пример #17
0
        public ActionResult Profil()
        {
            var userManager = MemberShipTools.NewUserManager();
            var user        = userManager.FindById(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId());
            var model       = new ProfilePasswordViewModel()
            {
                ProfileModel = new ProfilViewModel {
                    Id       = user.Id,
                    Email    = user.Email,
                    Name     = user.Name,
                    Surname  = user.Surname,
                    UserName = user.UserName
                }
            };

            return(View(model));
        }
Пример #18
0
        public ProfilePasswordViewModel ConvertProfile(ApplicationUser user)
        {
            ProfilePasswordViewModel 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(data);
        }
Пример #19
0
        public async Task <ActionResult> ChangePassword(ProfilePasswordViewModel model)
        {
            var userManager = UserManager;
            var id          = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();
            var user        = UserManager.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)
            {
                return(View("UserProfile", model));
            }

            var result = await userManager.ChangePasswordAsync(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId(),
                                                               model.changePasswordView.OldPassword,
                                                               model.changePasswordView.NewPassword);

            if (result.Succeeded)
            {//mail gönder
                var emailService = new EmailService();
                var body         = $"Merhaba <b>{user.Name}  {user.Surname}</b> <br/> <p>Hesabınızın şifresi güncellenmiştir.</p>";
                await emailService.SendAsync(new IdentityMessage()
                {
                    Body = body, Subject = "Sitemize Hoşgeldiniz"
                }, user.Email);

                return(RedirectToAction("Logout", "Account"));
            }
            return(View("UserProfile", model));
        }
        public async Task <ActionResult> UpdateProfile(ProfilePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("UserProfile", model));
            }

            try
            {
                var userManager = NewUserManager();
                var user        = await userManager.FindByIdAsync(model.UserProfileViewModel.Id);

                user.Name    = model.UserProfileViewModel.Name;
                user.Surname = model.UserProfileViewModel.Surname;
                if (user.Email != model.UserProfileViewModel.Email)
                {
                    //todo tekrardan aktivasyon gönderilmeli ve kullanıcı rolü aktif olamayan bir kullanıcı rolüne atanmalı!
                }
                user.Email       = model.UserProfileViewModel.Email;
                user.PhoneNumber = model.UserProfileViewModel.PhoneNumber;
                await userManager.UpdateAsync(user);

                TempData["Message"] = "Profiliniz güncellenmiştir";
                return(RedirectToAction("UserProfile"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #21
0
        public async Task <ActionResult> UserProfile()
        {
            try
            {
                ApplicationUser user = await _membershipTools.UserManager.GetUserAsync(HttpContext.User);

                ProfilePasswordViewModel 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/user.png" : user.AvatarPath,
                        Latitude    = user.Latitude,
                        Longitude   = user.Longitude
                    }
                };

                return(View(data));
            }
            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #22
0
        public async Task <ActionResult> UpdateProfile(ProfilePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("UserProfile", model));
            }

            try
            {
                var userManager = NewUserManager();
                var user        = await userManager.FindByIdAsync(model.UserProfileViewModel.Id);

                user.Name        = model.UserProfileViewModel.Name;
                user.Surname     = model.UserProfileViewModel.Surname;
                user.PhoneNumber = model.UserProfileViewModel.PhoneNumber;
                if (user.Email != model.UserProfileViewModel.Email)
                {
                }
                user.Email = model.UserProfileViewModel.Email;

                if (model.UserProfileViewModel.PostedFile != null &&
                    model.UserProfileViewModel.PostedFile.ContentLength > 0)
                {
                    var    file     = model.UserProfileViewModel.PostedFile;
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    string extName  = Path.GetExtension(file.FileName);
                    fileName  = StringHelpers.UrlFormatConverter(fileName);
                    fileName += StringHelpers.GetCode();
                    var klasoryolu = Server.MapPath("~/Upload/");
                    var dosyayolu  = Server.MapPath("~/Upload/") + fileName + extName;

                    if (!Directory.Exists(klasoryolu))
                    {
                        Directory.CreateDirectory(klasoryolu);
                    }
                    file.SaveAs(dosyayolu);

                    WebImage img = new WebImage(dosyayolu);
                    img.Resize(250, 250, false);
                    img.AddTextWatermark("Wissen");
                    img.Save(dosyayolu);
                    var oldPath = user.AvatarPath;
                    user.AvatarPath = "/Upload/" + fileName + extName;

                    System.IO.File.Delete(Server.MapPath(oldPath));
                }


                await userManager.UpdateAsync(user);

                TempData["Message"] = "Güncelleme işlemi başarılı";
                return(RedirectToAction("UserProfile"));
            }
            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #23
0
        public async Task <ActionResult> UserProfile(ProfilePasswordViewModel model)
        {
            ApplicationUser user = await _membershipTools.UserManager.FindByIdAsync(model.UserProfileViewModel.Id);

            if (!ModelState.IsValid)
            {
                return(View("UserProfile", model));
            }

            if (model.UserProfileViewModel.PostedFile != null &&
                model.UserProfileViewModel.PostedFile.Length > 0)
            {
                var    file     = model.UserProfileViewModel.PostedFile;
                string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                string extName  = Path.GetExtension(file.FileName);
                fileName  = StringHelpers.UrlFormatConverter(fileName);
                fileName += StringHelpers.GetCode();

                var webpath       = _hostingEnvironment.WebRootPath;
                var directorypath = Path.Combine(webpath, "Uploads");
                var filePath      = Path.Combine(directorypath, fileName + extName);


                if (!Directory.Exists(directorypath))
                {
                    Directory.CreateDirectory(directorypath);
                }

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }

                var oldPath = user.AvatarPath;
                if (oldPath != "/assets/img/user.png")
                {
                    System.IO.File.Delete(Path.Combine(oldPath));
                }
                user.AvatarPath = "/Uploads/" + fileName + extName;
            }

            try
            {
                user.Name        = model.UserProfileViewModel.Name;
                user.Surname     = model.UserProfileViewModel.Surname;
                user.PhoneNumber = model.UserProfileViewModel.PhoneNumber;
                if (User.IsInRole("Technician"))
                {
                    user.TechnicianStatus = model.UserProfileViewModel.TechnicianStatus;
                    user.Latitude         = model.UserProfileViewModel.Latitude;
                    user.Longitude        = model.UserProfileViewModel.Longitude;
                }
                if (user.Email != model.UserProfileViewModel.Email)
                {
                    //todo tekrar aktivasyon maili gönderilmeli. rolü de aktif olmamış role çevrilmeli.
                }
                user.Email = model.UserProfileViewModel.Email;

                await _membershipTools.UserManager.UpdateAsync(user);

                TempData["Message"] = "Güncelleme işlemi başarılı.";
                return(RedirectToAction("UserProfile"));
            }
            catch (Exception ex)
            {
                var mdl = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = "500"
                };
                TempData["ErrorMessage"] = JsonConvert.SerializeObject(mdl);
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #24
0
        public async Task <ActionResult> UpdateProfile(ProfilePasswordViewModel _model)
        {
            var model = _model.UserProfileViewModel;
            var user  = await _membershipTools.UserManager.FindByIdAsync(model.Id);

            if (model.PostedFile != null &&
                model.PostedFile.Length > 0)
            {
                var    file     = model.PostedFile;
                string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                string extName  = Path.GetExtension(file.FileName);
                fileName  = StringHelpers.UrlFormatConverter(fileName);
                fileName += StringHelpers.GetCode();

                var webpath       = _hostingEnvironment.WebRootPath;
                var directorypath = Path.Combine(webpath, "Uploads");
                var filePath      = Path.Combine(directorypath, fileName + extName);

                if (!Directory.Exists(directorypath))
                {
                    Directory.CreateDirectory(directorypath);
                }

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }

                user.AvatarPath = "/Uploads/" + fileName + extName;
            }

            try
            {
                user.Name        = model.Name;
                user.Surname     = model.Surname;
                user.PhoneNumber = model.PhoneNumber;
                //user.Location = model.Location;
                if (user.Email != model.Email)
                {
                    //todo tekrar aktivasyon maili gönderilmeli. rolü de aktif olmamış role çevrilmeli.
                }

                user.Email = model.Email;

                await _membershipTools.UserManager.UpdateAsync(user);

                TempData["Message"] = "Güncelleme işlemi başarılı.";
                return(RedirectToAction("UserProfile"));
            }
            catch (Exception ex)
            {
                TempData["Message"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu: {ex.Message}",
                    ActionName     = "UserProfile",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(View("UserProfile", _model));
            }
        }