Esempio n. 1
0
        public ActionResult SignInHandler(AuthAttempt authAttempt)
        {
            if (ModelState.IsValid)
            {
                // check if the credentials are right
                // and store user in session
                using (var ctx = new CarAuctionContext())
                {
                    try
                    {
                        User existingUser = ctx.Users.FirstOrDefault(
                            u => u.Email == authAttempt.Email && u.Password == authAttempt.Password
                            );
                        if (existingUser != null)
                        {
                            HttpContext.Session["User"] = existingUser;
                            Response.Redirect("/Panel");
                            return(null);
                        }
                    }
                    catch (InvalidOperationException ignored)
                    {
                    }
                }
            }

            ViewBag.FailureMessage = "Incorrect email or password";
            return(View());
        }
Esempio n. 2
0
 public bool AuthTokenValid([FromBody] AuthAttempt attempt)
 {
     if (attempt == null ||
         string.IsNullOrEmpty(attempt.Email) ||
         string.IsNullOrEmpty(attempt.AuthToken))
     {
         return(false);
     }
     return(!string.IsNullOrEmpty(GetUserId(attempt.Email, attempt.AuthToken)));
 }
Esempio n. 3
0
        public ActionResult In()
        {
            if (Session["user"] != null)
            {
                Response.Redirect("/Panel");
            }

            AuthAttempt authAttempt = new AuthAttempt();

            return(View(authAttempt));
        }
Esempio n. 4
0
        public bool LogOut([FromBody] AuthAttempt attempt)
        {
            if (attempt == null ||
                string.IsNullOrEmpty(attempt.Email) ||
                string.IsNullOrEmpty(attempt.AuthToken))
            {
                return(false);
            }
            User user = new User();

            user.Email = attempt.Email;
            user.Init();
            UserModel retrievedUser;

            UserModel.GetUser(user.Email, out retrievedUser);
            if (retrievedUser == null)
            {
                return(false);
            }
            retrievedUser.RemoveAuthToken(attempt.AuthToken);
            return(UserModel.UpdateUser(retrievedUser));
        }
Esempio n. 5
0
        private AuthAttempt CreateAndAddInProgressAuthorisation(string username)
        {
            lock (_inprogLock)
            {
                if (_inprogressAuthorisations.ContainsKey(username))
                {
                    return null;
                }
                else
                {
                    OAuthClientService oauthService = new OAuthClientService(Settings.ClientId, username);
                    AuthAttempt attempt = new AuthAttempt()
                    {
                        AuthService = oauthService,
                        Owner = username,
                        StartedAtUtc = DateTime.UtcNow
                    };
                    _inprogressAuthorisations.Add(username, attempt);

                    return attempt;
                }
            }
        }