Beispiel #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    TalkToAPI eKvizAPI = new TalkToAPI();

                    eKvizAPI.SendRequest(RequestType.CreateAccount, model.UserName,
                        new List<APIData>
                        {
                            new APIData {Name = "Password", Content = model.Password},
                            new APIData {Name = "FirstName", Content = model.FirstName},
                            new APIData {Name = "LastName", Content = model.LastName},
                            new APIData {Name = "JMBAG", Content = model.JMBAG}
                        });

                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);

                    WebSecurity.Logout();
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            TalkToAPI eKvizAPI = new TalkToAPI();

            HttpResponseMessage response = eKvizAPI.SendRequest(RequestType.Login, model.UserName, new List<APIData> {new APIData {Name = "Password", Content = model.Password}});

            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe) && response.StatusCode == HttpStatusCode.OK)
            {
                List<string> args = new List<string>();
                foreach (string arg in response.Content.ReadAsAsync<List<string>>().Result)
                {
                    args.Add(arg);
                }

                CreateAuthenticationTicket(args.First(), args.Last());
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }