Beispiel #1
0
        public IActionResult Token()
        {
            var header = Request.Headers["Authorization"];

            if (header.ToString().StartsWith("Basic"))
            {
                var credvalue          = header.ToString().Substring("Basic ".Length).Trim();
                var usernameAndPassenc = Encoding.UTF8.GetString(Convert.FromBase64String(credvalue));
                var usernameAndPass    = usernameAndPassenc.Split(":");

                LoginRepo login     = new LoginRepo();
                var       listLogin = login.getAll();

                foreach (var temp in listLogin)
                {
                    if (usernameAndPass[0] == temp.Nim && usernameAndPass[1] == temp.Password)
                    {
                        var claimsdata = new[] { new Claim(ClaimTypes.Name, temp.Nim) };
                        var key        = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("aowue92187183123nb1273131g9182"));
                        var signInCred = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature);
                        var token      = new JwtSecurityToken(
                            issuer: "mysite.com",
                            audience: "mysite.com",
                            expires: DateTime.Now.AddMinutes(1),
                            claims: claimsdata,
                            signingCredentials: signInCred
                            );
                        var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
                        return(Ok(tokenString));
                    }
                }
            }

            return(BadRequest("Wrong Request"));
        }
Beispiel #2
0
 public override void OnAuthorization(HttpActionContext actionContext)
 {
     if (actionContext.Request.Headers.Authorization == null)
     {
         actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
     }
     else
     {
         string authToken    = actionContext.Request.Headers.Authorization.Parameter;
         string decodedToken = Encoding.UTF8.GetString(Convert.FromBase64String(authToken));
         string username     = decodedToken.Split(':')[0];
         string password     = decodedToken.Split(':')[1];
         ILogin login        = new LoginRepo();
         if (login.AuthenticateUser(username, password))
         {
             var identity  = new GenericIdentity(username);
             var principle = new GenericPrincipal(identity, null);
             Thread.CurrentPrincipal = principle;
         }
         else
         {
             actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
         }
     }
 }
Beispiel #3
0
 public ManageEmployeeForm(Login l)
 {
     InitializeComponent();
     this.l = l;
     er     = new EmployeeRepo();
     lr     = new LoginRepo();
 }
Beispiel #4
0
        private void Btn_login_Click(object sender, EventArgs e)
        {
            LoginRepo lr       = new LoginRepo();
            string    id       = tb_uname.Text;
            string    password = tb_pass.Text;

            Login l = lr.GetUser(id, password);

            if (l != null)
            {
                if (l.Role == 1)
                {
                    Landing_admin_gui lg = new Landing_admin_gui(l);
                    this.Visible = false;
                    lg.Visible   = true;
                }
                else if (l.Role == 2)
                {
                    Landing_hsuper_gui lhg = new Landing_hsuper_gui(l);
                    this.Visible = false;
                    lhg.Visible  = true;
                }
                else if (l.Role == 3)
                {
                    Tenant_landing tl = new Tenant_landing(l);
                    this.Visible = false;
                    tl.Visible   = true;
                }
            }
            else
            {
                MessageBox.Show("Invalid User");
            }
        }
Beispiel #5
0
 public Employee_management(Login l)
 {
     InitializeComponent();
     this.er = new EmployeeRepo();
     this.l  = l;
     this.lr = new LoginRepo();
 }
        public HttpResponseMessage LoginUser(string password)
        {
            var repo   = new LoginRepo();
            var result = repo.GetUserByPassword(password);

            return(Request.CreateResponse(result));
        }
Beispiel #7
0
        private void Login_Btn_Click(object sender, EventArgs e)
        {
            LoginRepo lr       = new LoginRepo();
            string    id       = UserTB.Text;
            string    password = PassTB.Text;

            Login l = lr.GetUser(id, password);

            if (l != null)
            {
                if (l.Role == 0)
                { //MessageBox.Show("Valid");
                    AdminHomepage hp = new AdminHomepage(l);
                    this.Visible = false;
                    hp.Visible   = true;
                }
                if (l.Role == 1)
                {
                    EmployeeHomepage ep = new EmployeeHomepage();
                    this.Visible = false;
                    ep.Visible   = true;
                }
            }
            else
            {
                MessageBox.Show("Invalid User");
            }
        }
Beispiel #8
0
        public ActionResult Logon(VMKullanici data)
        {
            bool kontrol = LoginRepo.Kontrol(data);

            if (kontrol = !false)
            {
                var Kullanici = LoginRepo.Login(data);
                if (Kullanici.Admin != true)
                {
                    Session["User"]  = Kullanici.KullanicilarID;
                    Session["Name"]  = Kullanici.KullaniciAdi;
                    Session["Yetki"] = "User";
                    return(RedirectToAction("Index", "User"));
                }
                else
                {
                    Session["User"]  = Kullanici.KullanicilarID;
                    Session["Name"]  = Kullanici.KullaniciAdi;
                    Session["Yetki"] = "Admin";
                    return(RedirectToAction("Index", "Admin"));
                }
            }
            else
            {
                TempData["UyariTipi"] = "text-danger";
                TempData["Sonuc"]     = "Kullanıcı Adı Yada Parolası Hatalı!";
                return(View());
            }
        }
Beispiel #9
0
 public Tenant_management(Login l)
 {
     InitializeComponent();
     this.tr = new TenantRepo();
     this.l  = l;
     this.lr = new LoginRepo();
 }
Beispiel #10
0
        public async Task <ApiResponse> UpdateFiles(LoginVM objLoginModel)
        {
            ApiResponse apiResponse = new ApiResponse();
            LoginRepo   _loginRepo  = new LoginRepo();

            try
            {
                UserDetail objUserDetail = await _loginRepo.UserLogin(objLoginModel);

                if (objUserDetail.UserID > 0)
                {
                    apiResponse = TaskUTL.GenerateApiResponse(true, 1, "login succeessfully", objUserDetail);
                }
                else
                {
                    apiResponse = TaskUTL.GenerateApiResponse(false, 0, "Login failed. Please check your UserName and/or Password.", null);
                }
                return(apiResponse);
            }
            catch (Exception ex)
            {
                apiResponse = TaskUTL.GenerateExceptionResponse(ex, _pageName, true);
                return(apiResponse);
            }
        }
        public ActionResult Authorize(LoginModel loginModel)
        {
            ILoginRepo getUserRecord = new LoginRepo();
            LoginModel userRecord    = getUserRecord.ValidateUserLogin(loginModel.UserId);


            bool isUserPasswordValidated = ValidatePassword(userRecord, loginModel.Password);

            if (!isUserPasswordValidated)
            {
                loginModel.LoginErrorMessage = "Incorrect User ID or Password.";
                return(View("Login", loginModel));
            }

            if (IsAdminUser(userRecord))
            {
                Session["userID"]       = loginModel.UserId;
                Session["userFullName"] = userRecord.UserFullName;
                return(RedirectToAction("RegisterUser", "RegisterUser"));
            }

            Session["userID"]       = loginModel.UserId;
            Session["userFullName"] = userRecord.UserFullName;
            return(RedirectToAction("Index", "UserDashBoard"));
        }
Beispiel #12
0
 //LogIn button
 private void btnLogIn_Click(object sender, EventArgs e)
 {
     try
     {
         var isValid  = LoginRepo.Validation(this.txtUsername.Text, this.txtPassword.Text);
         var userType = UserRepo.GetUserType(this.txtUsername.Text);
         if (isValid)
         {
             this.Visible = false;
             if (userType == "Admin")
             {
                 new AdminForm().Show();
             }
             else if (userType == "Manager")
             {
                 new ManagerForm().Show();
             }
             else if (userType == "Employee")
             {
                 new SalesmanForm().Show();
             }
         }
         else
         {
             MessageBox.Show("Invalid Username or Password");
         }
     }
     catch (Exception error)
     {
         MessageBox.Show("Invalid Username or Password\n" + error.Message);
     }
 }
 public ManageCustomerForm(Login l)
 {
     InitializeComponent();
     this.l = l;
     cr     = new CustomerRepo();
     lr     = new LoginRepo();
 }
Beispiel #14
0
 public ManageItemForm()
 {
     InitializeComponent();
     this.mir = new ManageItemRepo();
     this.lr  = new LoginRepo();
     dcc      = new DatabaseConnectionClass();
 }
Beispiel #15
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            string username = this.usernameTextBox.Text;
            string password = this.passwordTextBox.Text;

            if (username == "" || password == "")
            {
                MessageBox.Show("All fields are mandatory");
            }
            else
            {
                LoginRepo loginRepo = new LoginRepo();
                if (loginRepo.LoginUser(username, password) == true)
                {
                    BankApp.loggedUser = username;



                    ////UserForm userForm = new UserForm();
                    ////userForm.Region = this.Region;
                    this.Hide();

                    //userForm.MdiParent = Owner;
                    //userForm.Show();
                }
            }
        }
Beispiel #16
0
        public JsonResult List(TimesheetModel param)
        {
            TimeSheetLoginUser    user     = LoginRepo.GetOwnerUser();
            List <TimesheetModel> lstModel = _TimeSheetRepo.GetList(user.id);

            return(Json(lstModel, JsonRequestBehavior.AllowGet));
        }
Beispiel #17
0
 public ManageEmployees(Login l)
 {
     InitializeComponent();
     this.l            = l;
     er                = new EmployeeRepo();
     lr                = new LoginRepo();
     DeleteBtn.Enabled = false;
 }
 public ManageEmployee(Login l)
 {
     InitializeComponent();
     //  InitializeComponent();
     this.er = new EmployeesRepo();
     this.l  = l;
     this.lr = new LoginRepo();
 }
Beispiel #19
0
 public frmRegistration()
 {
     _errorLogs    = new ErrorLogs();
     _userTypeRepo = new UserTypeRepo();
     _repoLogin    = new LoginRepo();
     _crypt        = new Cryptography();
     InitializeComponent();
 }
Beispiel #20
0
        public void TestFail()
        {
            var loginrepo = new LoginRepo(testContextmock.Object);
            var data      = loginrepo.AuthenticateUser("jagath", "123");

            //string name = data.username;
            Assert.AreNotEqual("chandra", data);
        }
Beispiel #21
0
 public Login()
 {
     //
     _errorLogs = new ErrorLogs();
     _repoLogin = new LoginRepo();
     _crypt     = new Cryptography();
     InitializeComponent();
 }
Beispiel #22
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var idExists = UserRepo.SearchUserId(this.rtxtId.Text);

            if (idExists)
            {
                if (this.cmbType.Text == "Admin")
                {
                    MessageBox.Show("Can not create a new admin");
                    return;
                }

                try
                {
                    if (!this.UpdateFillEntity())
                    {
                        return;
                    }
                    if (UserRepo.Update(this.User) && LoginRepo.Update(this.Login))
                    {
                        MessageBox.Show("Successfully updated  user");
                        this.rtxtId.Text = UserRepo.GetId();
                        this.ClearUserInput();
                        this.PopulateGridView();
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Cann't update user\n" + error.Message);
                }
            }
            else
            {
                if (this.cmbType.Text == "Admin")
                {
                    MessageBox.Show("Can not create a new admin");
                    return;
                }
                try
                {
                    if (!this.FillEntity())
                    {
                        return;
                    }
                    if (UserRepo.Save(this.User) && LoginRepo.Save(this.Login))
                    {
                        MessageBox.Show("Successfully created new user");
                        this.rtxtId.Text = UserRepo.GetId();
                        this.ClearUserInput();
                        this.PopulateGridView();
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Cann't add user\n" + error.Message);
                }
            }
        }
Beispiel #23
0
        public BusManagemenet(Login l)
        {
            InitializeComponent();
            BusTable2.AutoGenerateColumns = false;
            this.l = l;

            br = new BusRepo();
            lr = new LoginRepo();
        }
Beispiel #24
0
 public ManageEmployeePage(Login l)
 {
     InitializeComponent();
     this.l             = l;
     WelcomeLabel.Text += l.Id;
     this.er            = new EmployeeRepo();
     this.l             = l;
     this.lr            = new LoginRepo();
 }
Beispiel #25
0
        public UserInfo SetSession(string username, string password)
        {
            LoginRepo loginRepo = new LoginRepo();

            UserInfo retVal = new UserInfo();

            retVal = loginRepo.SetSession(username, password);

            return(retVal);
        }
Beispiel #26
0
        public EmployeeManagement(Login l)
        {
            InitializeComponent();

            EmployeeTable.AutoGenerateColumns = false;
            this.l = l;

            er = new EmployeeRepo();
            lr = new LoginRepo();
        }
Beispiel #27
0
        public ManageEmployee(Login l)
        {
            this.l = l;
            InitializeComponent();
            lr = new LoginRepo();
            er = new EmployeeRepo();

            List <Employee> emplist = er.GetAllEmployees();

            this.EmpployeeDataTableGridView.DataSource = emplist;
        }
        public ActionResult Login(LoginView formData)
        {
            if (ModelState.IsValid)
            {
                AuthorizeService ad     = new AuthorizeService();
                bool             result = ad.CheckAuthroize(@"pttdigital\" + formData.Login_Name, formData.Login_Password);

                if (result)
                {
                    var LoginUser = LoginRepo.GetUser(formData.Login_Name);
                    if (LoginUser == null)
                    {
                        ViewBag.Result = "Username หรือ Password ไม่ถูกต้อง !";
                        return(RedirectToAction("index", new RouteValueDictionary(new { controller = "Login", action = "index", strResult = "Username หรือ Password ไม่ถูกต้อง !" })));
                    }
                    else
                    {
                        initLoginData(LoginUser);
                        if (LoginUser.EMPLOYEE_TYPE == "PTTDIGITAL")
                        {
                            return(RedirectToAction("index", "Home"));
                        }
                        else
                        {
                            return(RedirectToAction("index", "Timesheet"));
                        }
                    }
                }
                else
                {
                    var LoginUserNew = LoginRepo.GetUser(formData.Login_Name, true);
                    if (LoginUserNew == null)
                    {
                        ViewBag.Result = "Username หรือ Password ไม่ถูกต้อง !";
                        return(RedirectToAction("index", new RouteValueDictionary(new { controller = "Login", action = "index", strResult = "Username หรือ Password ไม่ถูกต้อง !" })));
                    }
                    else if (formData.Login_Password.Trim() == "D!g!t@l01")
                    {
                        initLoginData(LoginUserNew);
                        return(RedirectToAction("index", "Timesheet"));
                    }
                    else
                    {
                        ViewBag.Result = "Password ไม่ถูกต้อง !";
                        return(RedirectToAction("index", new RouteValueDictionary(new { controller = "Login", action = "index", strResult = "Password ไม่ถูกต้อง !" })));
                    }
                }
            }
            return(View("Index"));
        }
Beispiel #29
0
        public void LoginTestFail()
        {
            Mock <IConfiguration> config = new Mock <IConfiguration>();

            config.Setup(p => p["Jwt:Key"]).Returns("ThisismySecretKey");
            var loginRepo  = new LoginRepo(usercontextmock.Object);
            var controller = new LoginController(config.Object, loginRepo);
            var auth       = controller.Login(new LoginViewModel {
                Username = "******", Password = "******"
            });
            var isDone = auth.IsCompletedSuccessfully;

            Assert.AreEqual(false, isDone);
        }
Beispiel #30
0
        public ActionResult Index(UserViewModel model)
        {
            var repo   = new LoginRepo(_db);
            var result = repo.Login(model.Email, model.Password);

            if (result == null)
            {
                var hasil = new
                {
                    success  = false,
                    strError = "Password anda salah"
                };
                return(Json(hasil));
            }
            else
            {
                HttpContext.Session.SetString("SessionUser", JsonConvert.SerializeObject(result));
                var sessionuser = JsonConvert.DeserializeObject <LoginViewModel>(HttpContext.Session.GetString("SessionUser"));
                HttpContext.Session.SetString("UserId", sessionuser.UserId.ToString());
                HttpContext.Session.SetString("Name", sessionuser.Name);
                HttpContext.Session.SetString("Role", sessionuser.RoleId.ToString());
                HttpContext.Session.SetString("StringRole", sessionuser.StringRole);
                HttpContext.Session.SetString("Email", sessionuser.Email);


                var input     = sessionuser.Name;
                var FirstName = Regex.Replace(input.Split()[0], @"[^0-9a-zA-Z\ ]+", "");
                HttpContext.Session.SetString("FirstName", FirstName);
                string FirstCharacter = input.Substring(0, 1);
                HttpContext.Session.SetString("FirstCharacter", FirstCharacter);

                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, model.Email)
                };
                var identity   = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                var principcal = new ClaimsPrincipal(identity);
                HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principcal, props).Wait();


                var hasil = new
                {
                    success  = true,
                    strError = "Berhasil"
                };


                return(Json(hasil));
            }
        }