예제 #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));
        }
        public void AddUpdateDeleteUser()
        {
            userRepository = new MessagingRepository <User>(dbSettings);
            user           = new User {
                Id = 1, Login = "******"
            };
            userRepository.Add(user);
            userRepository.Save();

            var userFromDb = userRepository.GetItem(1);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(userFromDb.Id, 1);
            Assert.AreEqual(userFromDb.Login, "NK");

            user.Login = "******";
            userRepository.Update(user);
            userRepository.Save();

            userFromDb = userRepository.GetItem(1);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual(userFromDb.Id, 1);
            Assert.AreEqual(userFromDb.Login, "neNK");

            userRepository.DeleteItem(1);
            userRepository.Save();

            userFromDb = userRepository.GetItem(1);

            Assert.IsNull(userFromDb);

            userRepository.Dispose();
        }
예제 #3
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());
        }
예제 #4
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());
            }
        }
        public void AddUpdateDeleteMessage()
        {
            messageRepository = new MessagingRepository <Message>(dbSettings);
            message           = new Message {
                Id = 1, UserId = 1, Text = "NK"
            };
            messageRepository.Add(message);
            messageRepository.Save();

            var messageFromDb = messageRepository.GetItem(1);

            Assert.IsNotNull(messageFromDb);
            Assert.AreEqual(messageFromDb.Id, 1);
            Assert.AreEqual(messageFromDb.UserId, 1);
            Assert.AreEqual(messageFromDb.Text, "NK");

            message.Text = "neNK";
            messageRepository.Update(message);
            messageRepository.Save();

            messageFromDb = messageRepository.GetItem(1);

            Assert.IsNotNull(messageFromDb);
            Assert.AreEqual(messageFromDb.Id, 1);
            Assert.AreEqual(messageFromDb.UserId, 1);
            Assert.AreEqual(messageFromDb.Text, "neNK");

            messageRepository.DeleteItem(1);
            messageRepository.Save();

            messageFromDb = messageRepository.GetItem(1);

            Assert.IsNull(messageFromDb);

            messageRepository.Dispose();
        }