示例#1
0
        public ActionResult Singup(UserProfileModel user)
        {
            if (ModelState.IsValid)
            {
                var existedUser = _userService.GetUserEntity(user.Email);
                if (existedUser == null)
                {
                    CreateUser(user);

                    var createdUser = _userService.GetUserEntity(user.Email);
                    CreateUserAvatar(createdUser);
                }
            }
            FormsAuthentication.SetAuthCookie(user.Email, true);
            return RedirectToAction("Main", "Main");
        }
示例#2
0
 public ActionResult Singin(UserProfileModel user)
 {
     if (ModelState.IsValid)
     {
         var existedUser = _userService.GetUserEntity(user.Email);
         if (existedUser != null)
         {
             var singinPassHash = GetPasswordHash(user.Password, existedUser.Salt);
             if (singinPassHash == existedUser.Password)
             {
                 FormsAuthentication.SetAuthCookie(user.Email, true);
                 return RedirectToAction("Main", "Main");
             }
             ViewBag.ErrorMessage = "Неправильный адрес электронной почты или пароль. Попробуйте ещё раз.";
         }
         return RedirectToAction("Singup");
     }
     return View(user);
 }
        public ActionResult GetUserInfo()
        {
            string userEmail = HttpContext.User.Identity.Name;
            var user = _userService.GetUserEntity(userEmail);
            var avatar = _avatarService.GetByUserId(user.Id);
            if (avatar == null)
            {
                avatar = new AvatarServiceEntity()
                {
                    Image = AvatarCreator.Get(user.Name),
                };
            }

            var userProfile = new UserProfileModel()
            {
                Name = user.Name,
                Avatar = Convert.ToBase64String(avatar.Image),
            };

            return Json(userProfile, JsonRequestBehavior.AllowGet);
        }
示例#4
0
        private void CreateUser(UserProfileModel user)
        {
            var newServiceUser = user.ToServiceEntity();
            string salt = GetSalt();

            newServiceUser.Salt = salt;
            newServiceUser.Password = GetPasswordHash(user.Password, salt);

            _userService.CreateUser(newServiceUser);
        }