예제 #1
0
        public ActionResult Register()
        {
            AccountEditVM model = new AccountEditVM();

            TryUpdateModel(model);

            User         user        = new User();
            UsersService userService = new UsersService();

            if (userService.CheckUsernameOrMail(model) != null)
            {
                ModelState.AddModelError("", "Username or email already exists!");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            user.Username  = model.Username;
            user.Email     = model.Email;

            user.Password = Guid.NewGuid().ToString();
            userService.Save(user);
            EmailService.SendEmail(user, ControllerContext);

            return(this.RedirectToAction("Login"));
        }
예제 #2
0
        public ActionResult Register()
        {
            AccountEditVM model = new AccountEditVM();

            TryUpdateModel(model);

            PhoneBook.Models.User user        = new Models.User();
            UsersService          userService = new UsersService();

            if (userService.CheckUsernameOrMail(model) != null)
            {
                ModelState.AddModelError("", "Username or email already exists!");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Mapper.Map(model, user);

            user.Password = Guid.NewGuid().ToString();
            userService.Save(user);
            Task.Run(() => EmailService.SendEmail(user, ControllerContext));

            return(this.RedirectToAction(c => c.Login()));
        }
예제 #3
0
        public async Task <IActionResult> Edit(AccountEditVM model)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            string uniqueFileName = UploadedFile(model);

            if (user == null)
            {
                return(View("EditFailure"));
            }
            else
            {
                user.FirstName    = model.FirstName;
                user.LastName     = model.LastName;
                user.DisplayName  = model.DisplayName;
                user.PhoneNumber  = model.PhoneNumber;
                user.ProfileImage = uniqueFileName;

                var result = await _userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(View("EditConfirmation"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View(model));
            }
        }
예제 #4
0
        public User CheckUsernameOrMail(AccountEditVM user)
        {
            UsersService userService = new UsersService();
            User         userMail    = userService.GetAll().FirstOrDefault((u => u.Email == user.Email || u.Username == user.Username.ToLower()));

            if (userMail != null)
            {
                return(userMail);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        private string UploadedFile(AccountEditVM model)
        {
            string uniqueFileName = null;

            if (model.ProfileImage != null)
            {
                string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfileImage.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ProfileImage.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
예제 #6
0
        public async Task <IActionResult> Edit()
        {
            // Fetch the userprofile
            var user = await _userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                return(View("EditFailure"));
            }
            // Construct the viewmodel
            AccountEditVM model = new AccountEditVM();

            model.FirstName   = user.FirstName;
            model.LastName    = user.LastName;
            model.DisplayName = user.DisplayName;
            model.PhoneNumber = user.PhoneNumber;

            return(View(model));
        }
예제 #7
0
        public ActionResult Register(string str)
        {
            AccountEditVM model = new AccountEditVM();

            return(View(model));
        }