Ejemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                for (int i = 0; i <= repos.Count(); i++)
                {
                    User user = repos.GetItem(i);
                    if (model.Login == user.Login)
                    {
                        if (model.Password == user.Pass)
                        {
                            //login
                            await Authenticate(model.Login); // аутентификация

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Wrong Login or Password");
                            break;
                        }
                    }
                }
                ModelState.AddModelError("", "Wrong Login or Password");
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                int c = repos.Count();
                for (int i = 0; i <= c; i++)
                {
                    User user = repos.GetItem(i);
                    if (user != null)
                    {
                        if (Model.Login == user.Login)
                        {
                            //await Clients.Caller.SendAsync("ReceiveMessage", "This Login already exists");
                            ModelState.AddModelError("", "This Logis already exists");
                            return(Page());
                        }
                    }
                    if (i == c)
                    {
                        User nuser = new User();
                        nuser.Login = Model.Login;
                        nuser.Pass  = Model.Password;
                        nuser.Id    = c++;
                        repos.Add(nuser);
                        repos.Save();
                        await Authenticate(Model.Login); // аутентификация

                        return(RedirectToPage("/Chat"));
                    }
                }
            }
            ModelState.AddModelError("", "error");
            return(Page());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync()
        {
            if (ModelState.IsValid)
            {
                for (int i = 0; i < repos.Count(); i++)
                {
                    User user = repos.GetItem(i);
                    if (Model.Login == user.Login)
                    {
                        if (Model.Password == user.Pass)
                        {
                            //login
                            await Authenticate(Model.Login); // аутентификация

                            return(RedirectToPage("/chat"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Wrong Login or Password");
                            return(Page());
                        }
                    }
                }
                ModelState.AddModelError("", "Wrong Login or Password");
                return(Page());
            }
            else
            {
                return(Page());
            }
        }