private static void SetIdentity(AuthorizationContext filterContext, string validationToken)
        {
            var user = UserCore.GetSingle(usr => usr.AspNetUserId == validationToken, new[] { nameof(User.AspNetUser) });

            if (user == null)
            {
                return;
            }

            var identity = new CustomIdentity
            {
                AspNetUserId        = validationToken,
                Username            = user.AspNetUser.Email,
                Status              = user.AspNetUser.Status ?? user.AspNetUser.Status.Value,
                Id                  = user.Id,
                ProfilePictureUrl   = user.ProfilePictureUrl,
                UserType            = user.AspNetUser.UserType ?? user.AspNetUser.UserType.Value,
                FullName            = user.FullName,
                NumberOfMealsPerDay = user.NumberOfMealsPerDay.Value,
                BirthDay            = user.BirthDay.HasValue == true?user.BirthDay.Value.Date.ToString() : "1997/02/07",

                                          //NumberOfWorkoutsPerDay = user.NumberOfWorkoutsPerDay ?? user.NumberOfWorkoutsPerDay.Value,
            };

            SetIdentity(filterContext, identity, user.AspNetUser);
        }
Пример #2
0
        public void TestRegister()
        {
            var user = new UserViewModel()
            {
                FirstName = "Test",
                LastName  = "Test",
                Email     = "*****@*****.**",
                Password  = Md5Helper.Hash("6178")
            };

            var createdUser = UserCore.Create(user);

            Assert.AreEqual(true, createdUser.Success);

            var createdUserDb = UserCore.GetSingle(_user => _user.Email == user.Email);

            Assert.AreEqual(true, createdUser != null);
            Assert.AreEqual(user.FirstName, createdUserDb.FirstName, "FirstName");
            Assert.AreEqual(user.LastName, createdUserDb.LastName, "LastName");
            Assert.AreEqual(user.Password, createdUserDb.Password, "Passwords");

            var deleteUserResponse = UserCore.Delete(createdUserDb);

            Assert.AreEqual(true, deleteUserResponse);
        }
Пример #3
0
        public JsonResult Login(LoginModel model)
        {
            var response = ResponseFactory.Success(ResponseCode.SuccessLoggedIn);

            if (model == null)
            {
                return(Json(ResponseFactory.Error(ResponseCode.ErrorInvalidInput), JsonRequestBehavior.AllowGet));
            }

            var user = UserCore.GetSingle(userTemp => userTemp.Email == model.Email);

            if (user == null)
            {
                return(Json(ResponseFactory.Error(ResponseCode.ErrorEmailInvalid), JsonRequestBehavior.AllowGet));
            }

            var check = Md5Helper.VerifyPassword(model.Password, user.Password);

            if (check == false)
            {
                return(Json(ResponseFactory.Error(ResponseCode.ErrorInvalidPassword), JsonRequestBehavior.AllowGet));
            }

            if (user.IsAdmin == true)
            {
                Session["isAdmin"] = true;
            }
            Session["userId"]   = user.Id;
            Session["userName"] = user.FirstName;
            return(Json(response));
        }