private void BtnChangePwd_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Users u = new Users();
         u.LoginID  = (txtLoginID.Text);
         u.Password = txtNewPwd.Text;
         AuthenticationValidation av = new AuthenticationValidation();
         if (av.UpdateUser_BLL(u))
         {
             MessageBox.Show(string.Format("Password Changed Successfully"), "Change Password");
             txtLoginID.Clear();
             txtNewPwd.Clear();
         }
         else
         {
             MessageBox.Show(string.Format("User with Login Id does not exist"), "Change Password");
         }
     }
     catch (UsersException ex)
     {
         MessageBox.Show(ex.Message);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        public IHttpActionResult AddUser([FromBody] UserInfoDto userInfo)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var token = Request.GetAuthorizationHeader();

                if (!AuthenticationValidation.IsAdmin(token))
                {
                    return(Response(HttpStatusCode.Unauthorized, "Not allowed."));
                }
                if (_userService.AddUser(userInfo))
                {
                    return(Ok("add successed"));
                }
                return(BadRequest("add failed"));
            }
            catch (System.Exception e)
            {
                return(InternalServerError(e));
            }
        }
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            CustomerHome customer = new CustomerHome();

            try
            {
                Users newUser = new Users();
                AuthenticationValidation user = new AuthenticationValidation();
                newUser.LoginID = (txtloginID.Text);
                id = newUser.LoginID;
                newUser.Password = txtPassword.Password.ToString();
                string userRole = user.Login_BLL(newUser);
                if (userRole.ToLower() == "customer")
                {
                    MessageBox.Show(string.Format("Login Successful"), "Login Window");
                    customer.EmployeeMenu.Visibility = Visibility.Hidden;
                    customer.AdminMenu.Visibility    = Visibility.Hidden;
                    customer.Show();
                    Close();
                }
                else if (userRole.ToLower() == "employee")
                {
                    MessageBox.Show(string.Format("Login Successful"), "Login Window");
                    customer.CustomerMenu.Visibility = Visibility.Hidden;
                    customer.AdminMenu.Visibility    = Visibility.Hidden;
                    customer.Show();
                    Close();
                }
                else if (userRole.ToLower() == "admin")
                {
                    MessageBox.Show(string.Format("Login Successful"), "Login Window");
                    customer.CustomerMenu.Visibility = Visibility.Hidden;
                    customer.EmployeeMenu.Visibility = Visibility.Hidden;
                    customer.Show();
                    Close();
                }
                else
                {
                    MessageBox.Show(string.Format("Invalid Login"), "Login Window");
                }
            }
            catch (UsersException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeleteNews(int newsId)
        {
            var token = Request.GetAuthorizationHeader();

            if (AuthenticationValidation.IsAdminOrMod(token))
            {
                return(ResponseMessage(_newsService.Delete(newsId)
                    ? Request.CreateResponse(HttpStatusCode.OK, "News is deleted.")
                    : Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid news id.")));
            }

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden,
                                                          "Only admin or mod can delete a news.")));
        }
        public void AuthenticationValidation_AccountNotFound_Assert_False()
        {
            Account = new Account()
            {
                PIN         = 90565,
                Id          = 27056,
                TotalAmount = new Amount("USD", 500),
                ClientId    = 22
            };
            AccountBD = new Account();
            var stubRepo = new Mock <IAccountRepository>();

            stubRepo.Setup(s => s.FindAsync(27056)).ReturnsAsync(AccountBD);
            authenticationValidation = new AuthenticationValidation(stubRepo.Object);
            Assert.IsFalse(authenticationValidation.IsSatisfiedBy(Account));
        }
        public IHttpActionResult GetUsers()
        {
            try
            {
                var token = Request.GetAuthorizationHeader();

                if (!AuthenticationValidation.IsAdmin(token))
                {
                    return(Response(HttpStatusCode.Unauthorized, "Not allowed."));
                }
                return(Ok(_userService.GetUsers()));
            }
            catch (System.Exception e)
            {
                return(InternalServerError(e));
            }
        }
        public IHttpActionResult DeleteUsers(int userId)
        {
            try
            {
                var token = Request.GetAuthorizationHeader();

                if (!AuthenticationValidation.IsAdmin(token))
                {
                    return(Response(HttpStatusCode.Unauthorized, "Not allowed."));
                }
                if (_userService.DeleteUser(userId))
                {
                    return(Ok("delete successed"));
                }
                return(BadRequest("delete failed"));
            }
            catch (System.Exception e)
            {
                return(InternalServerError(e));
            }
        }
Ejemplo n.º 8
0
        public IHttpActionResult UpdateNews(int newsId, [FromBody] NewsDto news)
        {
            var token = Request.GetAuthorizationHeader();

            if (!AuthenticationValidation.IsAdminOrMod(token))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden,
                                                              "Only admin or mod can modify a news.")));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_newsService.UpdateNews(newsId, news))
            {
                return(Ok("News updated."));
            }

            return(BadRequest("Invalid news id."));
        }
Ejemplo n.º 9
0
        public IHttpActionResult AddNews([FromBody] NewsDto news)
        {
            var token = Request.GetAuthorizationHeader();

            if (!AuthenticationValidation.IsAdminOrMod(token))
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Forbidden,
                                                              "Only admin or mod can create a news.")));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_newsService.AddNews(news))
            {
                return(Ok("News created."));
            }

            return(BadRequest("An error occurred when adding news. Please try again."));
        }