コード例 #1
0
 private void GetCurrentUserInfo()
 {
     if (User != null)
         {
             AccountRepository accountRepository = new AccountRepository();
             _user.Username = User.Identity.Name;
             _user.AccountID = accountRepository.GetAccountIDByUserName(_user.Username);
             _user.IsModerator = User.IsInRole("Moderator");
         }
 }
コード例 #2
0
 // **************************************
 // URL: /Account/Activate/username/key
 // **************************************
 public ActionResult Activate(string username, string key)
 {
     AccountRepository _db = new AccountRepository();
     if (_db.ActivateUser(username, key) == false)
     {
         return RedirectToAction("Edit", "UserProfile", new { id = _db.GetAccountIDByUserName(username) });
     }
     else
     {
         return RedirectToAction("LogOn");
     }
 }
コード例 #3
0
        public ActionResult Accounts(string currentFilter, string searchString)
        {
            AccountRepository _accountRepository = new AccountRepository();

            if (Request.HttpMethod == "GET")
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            return View(_accountRepository.GetAllAccounts(searchString));
        }
コード例 #4
0
 public ViewResult Edit(int id)
 {
     AccountRepository _accountRepository = new AccountRepository();
     return View(_accountRepository.GetAccountByID(id));
 }
コード例 #5
0
 public ActionResult DeleteAccountConfirmed(int id)
 {
     AccountRepository _accountrepository = new AccountRepository();
     _accountrepository.RemoveAccountByID(id);
     return RedirectToAction("Accounts");
 }
コード例 #6
0
 public ActionResult Edit(Account account)
 {
     if (ModelState.IsValid)
     {
         AccountRepository _accountRepository = new AccountRepository();
         _accountRepository.SaveAccount(account);
     }
     return RedirectToAction("Accounts");
 }
コード例 #7
0
        public MembershipCreateStatus CreateUser(string userName, string password, string email, string firstName, string lastName, bool isApproved)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");
            if (String.IsNullOrEmpty(email)) throw new ArgumentException("Value cannot be null or empty.", "email");
            if (String.IsNullOrEmpty(firstName)) throw new ArgumentException("Value cannot be null or empty.", "firstName");
            if (String.IsNullOrEmpty(lastName)) throw new ArgumentException("Value cannot be null or empty.", "lastName");

            MembershipCreateStatus status;
            _provider.CreateUser(userName, password, email, null, null, isApproved, null, out status);

            if (status == MembershipCreateStatus.Success)
            {
                AccountRepository accountRepository = new AccountRepository();
                accountRepository.RegisterUserProfile(userName, firstName, lastName);
            }

            return status;
        }
コード例 #8
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        //route moderator to moderatorpage
                        AccountRepository _db = new AccountRepository();

                        if (Roles.IsUserInRole(model.UserName,"Moderator"))
                        {

                            return RedirectToAction("Accounts", "Moderator");
                        }
                        else
                        {
                            return RedirectToAction("Index", "UserProfile", new { id = _db.GetAccountIDByUserName(model.UserName) });
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }