//[ValidateAntiForgeryToken]
        public ActionResult Login(Login login)
        {
            bool hasAccess = AuthManager.AuthUser(login.Email, login.Password);

            login.Role = UserManager.GetRoleNamesByEmail(login.Email);


            if (hasAccess)
            {
                var authTicket = new FormsAuthenticationTicket(
                    1,                                          //Ticket Version
                    login.Email,                                //Userindentifizierung
                    DateTime.Now,                               //Zeitpunkt der Erstellung
                    DateTime.Now.AddMinutes(20),                //Gültigkeitsdauer
                    true,                                       //persistentes Ticket über Session hinweg
                    login.Role                                  //Userrolle(n)
                    );

                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);

                return(RedirectToAction("Index", "Home"));
            }

            var person = UserManager.GetPersonByEmail(User.Identity.Name);

            //Session.Add("ID", person.ID);
            //Session.Add("Gamertag", person.Gamertag);
            //Session.Add("CurrencyBalance", person.Currencybalance);
            return(RedirectToAction("Error", "Home"));
        }
Exemplo n.º 2
0
        public ActionResult Login(Login login)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(login));
                }
                else
                {
                    login.Role = UserManager.GetRoleByEmail(login.Email);
                    bool hasAccess = AuthManager.AuthUser(login.Email, login.Password);

                    //Authentifizierung
                    if (!hasAccess)
                    {
                        TempData["ErrorMessage"] = "Email oder Passwort falsch!";
                        return(View(login));
                    }
                    else
                    {
                        var authTicket = new FormsAuthenticationTicket(
                            1,                                //Ticketversion
                            login.Email,                      //UserIdentifizierung
                            DateTime.Now,                     //Zeitpunkt der Erstellung
                            DateTime.Now.AddMinutes(20),      //Gültigkeitsdauer
                            true,                             //Persistentes Ticket über Sessions hinweg
                            login.Role                        //Userrolle(n)
                            );

                        string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                        var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                        System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
                    }
                }



                string rolle = UserManager.GetRoleNamesByEMail(login.Email);
                AuthManager.AuthUser(login.Email, login.Password);
                string gamertag = UserManager.getGamerTagByEmail(login.Email);

                TempData["ConfirmMessage"] = "Willkomen" + " " + gamertag;
            }
            catch (Exception e)
            {
                if (e.Message == "UserDoesNotExist")
                {
                    TempData["ErrorMessage"] = "Email oder Passwort falsch!";
                }
                Writer.LogError(e);
                return(View(login));
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
        public void LogInWithIncorrectPassword()
        {
            RegistrationData authData = new RegistrationData("test3", "test3");

            TokenData tokenData = AuthManager.RegisterUser(authData);

            AuthManager.LogOutUser(tokenData);

            tokenData = AuthManager.AuthUser(authData);

            Assert.IsNotNull(tokenData);

            Assert.IsTrue(AuthManager.ValidateAuthToken(tokenData));
        }
        public ActionResult Login(User login)
        {
            try
            {
                bool hasAccess = AuthManager.AuthUser(login.Email, login.Password);
                login.Role = UserManager.GetRoleByUserEmail(login.Email);

                if (hasAccess)
                {
                    var authTicket = new FormsAuthenticationTicket(
                        1,                                          //Ticketversion
                        login.Email,                                //Useridentifizierung
                        DateTime.Now,                               //Zeitpunkt der Erstellung
                        DateTime.Now.AddMinutes(20),                //Gültigkeitsdauer
                        true,                                       //Persistentes Ticket über Session hinaus
                        login.Role                                  //Userrolle(n)
                        );

                    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                    System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
                }

                //Toastr Test
                //TempData["ConfirmMessage"] = "Test Test Test";

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                //Toastr Test
                //TempData["ErrorMessage"] = "FEHLER!";
                if (login.isActive == true)
                {
                    TempData["confLogin"] = "******";
                    return(RedirectToAction("Login", "Account"));
                }

                else
                {
                    TempData["confLogin"] = "******";
                    return(RedirectToAction("Login", "Account"));
                }
            }
        }
Exemplo n.º 5
0
 public TokenData Authorization([FromBody] AuthData data)
 {
     try
     {
         var token = AuthManager.AuthUser(data);
         token.UserType = UsersManager.GetUser(token).RootType;
         return(token);
     }
     catch (ArgumentException)
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(null);
     }
     catch (AuthExceptions.UserDoesNotExists)
     {
         Response.StatusCode = (int)HttpStatusCode.NotFound;
         return(null);
     }
     catch (AuthExceptions.IncorrectPassword)
     {
         Response.StatusCode = (int)HttpStatusCode.PreconditionFailed;
         return(null);
     }
 }
Exemplo n.º 6
0
        public void Test()
        {
            //Default Test User Creation
            {
                var token = AuthManager.RegisterUser(new RegistrationData("user", "password")
                {
                    RootType = RootEnum.Candidate
                });

                TestsManager.CreateTest(new TestData
                {
                    Name      = "English",
                    Questions = new TestData.Question[2]
                    {
                        new TestData.Question
                        {
                            Answers = new TestData.Question.Answer[3]
                            {
                                new TestData.Question.Answer
                                {
                                    AnswerText = "A or b",
                                    IsCorrect  = true
                                },
                                new TestData.Question.Answer
                                {
                                    AnswerText = "nor A , nor b",
                                    IsCorrect  = true
                                },
                                new TestData.Question.Answer
                                {
                                    AnswerText = "A and B",
                                    IsCorrect  = false
                                }
                            },
                            QuestionText = "A or B is good letters?"
                        },
                        new TestData.Question
                        {
                            Answers = new TestData.Question.Answer[3]
                            {
                                new TestData.Question.Answer
                                {
                                    AnswerText = "A or C",
                                    IsCorrect  = true
                                },
                                new TestData.Question.Answer
                                {
                                    AnswerText = "nor A , nor C",
                                    IsCorrect  = true
                                },
                                new TestData.Question.Answer
                                {
                                    AnswerText = "A and C",
                                    IsCorrect  = false
                                }
                            },
                            QuestionText = "A or C is good letters?"
                        },
                    }
                });

                ProgramsManager.CreateProgram(new Model.Programs.ProgramData()
                {
                    Name   = "Bachelor 1st year",
                    Course = "Bachelor",
                });

                ProgramsManager.AssignTestToProgram(new TestAssigningData()
                {
                    ProgramId = ProgramsManager.Instance._programs.First().Id,
                    TestId    = TestsManager.Instance.Tests.First().TestId,
                });

                token = AuthManager.AuthUser(new AuthData("user", "password"));

                ProgramsManager.AssignCandidateToProgram(new UserAssigningData()
                {
                    CandidateId = UsersManager.GetUser(token).Id,
                    ProgramId   = ProgramsManager.Instance._programs.First().Id,
                });

                AuthManager.LogOutUser(token);
            }


            //Admin Creation
            {
                var token = AuthManager.RegisterUser(new RegistrationData("admin", "admin")
                {
                    RootType = RootEnum.Admin
                });

                AuthManager.LogOutUser(token);
            }

            //Manager Creation
            {
                var token = AuthManager.RegisterUser(new RegistrationData("manager", "manager")
                {
                    RootType = RootEnum.Manager
                });

                AuthManager.LogOutUser(token);
            }

            //Interviewer Creation
            {
                var token = AuthManager.RegisterUser(new RegistrationData("interviewer", "interviewer")
                {
                    RootType = RootEnum.Interviewer
                });

                AuthManager.LogOutUser(token);
            }
        }