Exemplo n.º 1
0
 private async Task SignInAsync(User user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
 }
Exemplo n.º 2
0
        public ActionResult CreateUser(RegisterViewModel model)
        {
            if (model != null)
            {

                var user = new User()
                {
                    UserName = model.UserName,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Address = model.Address,
                    Email = model.Email,
                    Phone = model.Phone,
                    AccountType = model.AccountType,
                    Suspend = false


                };
                var result = UserManager.Create(user, model.Password);
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            return Json(false, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 3
0
 public ActionResult DeleteUser(User model)
 {
     if (model != null)
     {
         userService.DeleteUser(model);
         return Json(true, JsonRequestBehavior.AllowGet);
     }
     return Json(false, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 4
0
 public ActionResult EditProfile(User user)
 {
     if (user != null)
     {
         userService.UpdateUserInfo(user);
         return Json(true, JsonRequestBehavior.AllowGet);
     }
     return Json(false, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Build User View Model
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private UserViewModel CreateUserViewModel(User user)
        {
            return new UserViewModel()
                {
                    Id = user.Id,
                    ContactTitle = user.ContactTitle,
                    UserName = user.UserName,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Address = user.Address,
                    Email = user.Email,
                    Suspend = user.Suspend,
                    AccountType = user.AccountType,
                    AccountTypeName = user.AccountType.ToString(),
                    MembershipPackageId = user.MembershipPackageId,
                    PaymentMethod = user.PaymentMethod,
                    PaymentPeriod = user.PaymentPeriod,
                    ExperiodDate = user.ExpireDate,
                    StartDate = user.StartDate,
                    PasswordHash = user.PasswordHash,
                    SecurityStamp = user.SecurityStamp,
                    ProfileImageUrl = !String.IsNullOrEmpty(user.ProfileImage) ? user.ProfileImage : "/Upload/no-img.jpg",
                    Phone = user.Phone,
                    Tips = user.BusinessComments.Select(t => new BusinessCommentViewModel()
                    {

                        Id = t.Id,
                        Comment = t.Comment,
                        CreateDate = t.CreateDate,
                        BusinessId = t.BusinessId,
                        BusinessName = t.Business.Name,
                        BusinessAddress = t.Business.Address,
                        ImgProfile = t.Business.ImgProfile
                    }).ToList(),
                    TotalCheckins = user.TotalCheckins

                };
        }
Exemplo n.º 6
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new User()
                {
                    UserName = model.UserName,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Address = model.Address,
                    Phone = model.Phone,
                    Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Exemplo n.º 7
0
        public JsonResult GetCurrentUser()
        {
            var userId = User.Identity.GetUserId();
            var users = userService.Get().Where(t => t.Id.Equals(userId))
               .FirstOrDefault();
            if (users != null)
            {
                var result = new User()
                {
                    AccessFailedCount = users.AccessFailedCount,
                    AccountType = users.AccountType,
                    Address = users.Address,

                    ContactTitle = users.ContactTitle,
                    Email = users.Email,
                    EmailConfirmed = users.EmailConfirmed,
                    ExpireDate = users.ExpireDate,
                    FirstName = users.FirstName,
                    Gender = users.Gender,
                    Id = users.Id,
                    LastName = users.LastName,
                    LockoutEnabled = users.LockoutEnabled,
                    LockoutEndDateUtc = users.LockoutEndDateUtc,
                    MembershipPackageId = users.MembershipPackageId,
                    Phone = users.Phone,
                    PhoneNumber = users.PhoneNumber,
                    PhoneNumberConfirmed = users.PhoneNumberConfirmed,
                    ProfileImage = users.ProfileImage,
                    SecurityStamp = users.SecurityStamp,
                    StartDate = users.StartDate,
                    Status = users.Status,
                    Suspend = users.Suspend,
                    Tips = users.Tips,
                    TwoFactorEnabled = users.TwoFactorEnabled,
                    UserName = users.UserName,
                    PasswordHash = users.PasswordHash

                };
                users = result;
            }
            return Json(users, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 8
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User()
                {
                    UserName = model.UserName,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Address = model.Address,
                    Email = model.Email,
                    AccountType = AccountType.User

                };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await UserManager.AddToRoleAsync(user.Id, AccountType.User.ToString());
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Create User
 /// </summary>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public bool CreateUser(User user, string password)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
        /// <summary>
        /// Update User Info
        /// </summary>
        /// <param name="user"></param>
        public void UpdateUserInfo(User user)
        {
            if (user.ExpireDate == DateTime.MinValue)
                user.ExpireDate = DateTime.Now;
            if (user.StartDate == DateTime.MinValue)
                user.StartDate = DateTime.Now;

                using (var dbContext = new DatabaseContext())
                {
                    var _user = dbContext.Users.FirstOrDefault(t=>t.Id.Equals(user.Id));
                    if(_user != null)
                    {
                        _user.IsOnline = user.IsOnline;
                        dbContext.SaveChanges();
                    }
                }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool DeleteUser(User user)
        {
            using (var dbContext = new DatabaseContext())
            {

                var rDel = dbContext.Users.Include(t => t.Roles).FirstOrDefault(r => r.Id.Equals(user.Id));

                if (rDel != null)
                {
                    dbContext.Users.Remove(rDel);
                    dbContext.SaveChanges();
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Create User
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool CreateUser(User user)
 {
     return accountRepository.Add(user) != null;
 }