Ejemplo n.º 1
0
        public ActionResult EditUser(string id)
        {
            IDAL dal = new DBDataAL();
            string userName = id;
            userName = userName ?? "";
            bool requestHasError = false;
            User user = dal.GetUser(userName);

            if (dal.isInRole(userName, "Admin")
                && User.Identity.Name != userName)
            {
                ViewBag.AdminError = userName + " is an admin and you are currently logged in as " + User.Identity.Name
                    + ". To edit this user, please log in to that account.";
                requestHasError = true;
            }
            else if (user == null)
            {
                ViewBag.AdminError = "User was not found";
                requestHasError = true;
            }

            ActionResult view = null;
            if(!requestHasError)
                view = View(new UserViewModel(user));
            else
                view = View("~/Views/Admin/AdminError.cshtml");

            return view;
        }
Ejemplo n.º 2
0
		//[ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var result = await SignInManager.PasswordSignInAsync(model.LoginUserName, model.LoginPassword, isPersistent: true, shouldLockout: false);
            switch (result)
            {
				case SignInStatus.Success:
				{
					if (returnUrl != null)
						return RedirectToLocal(returnUrl);
					else
					{
						IDAL dal = new DBDataAL();
						bool isAdmin = dal.isInRole(model.LoginUserName, "Admin");
						return RedirectAfterLogin(isAdmin);
					}
				}
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = true });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
					return View(new MembershipModel { Register = new RegisterModel(), Login = model });
            }
        }
Ejemplo n.º 3
0
		//[ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterModel model)
        {
			this.validateRegisterModel(model);
            if (ModelState.IsValid)
            {
                var user = new LogUser { UserName = model.RegisterUserName };
                var result = await UserManager.CreateAsync(user, model.RegisterPassword);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    IDAL dal = new DBDataAL();
                    dal.CreateUser(new User() { UserName = user.UserName, Attack = 1, Defense = 1 });
					//Passing in whether or not the user is an admin
					return RedirectAfterLogin(dal.isInRole(user.UserName, "Admin"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View("~/Views/Membership/Login.cshtml");
        }