public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            int statusLoggin = userBUS.CheckLogin(context.UserName, context.Password);

            if (statusLoggin == 0)
            {
                var role     = userBUS.GetPermission(context.UserName);
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.Role, role.RoleName));
                identity.AddClaim(new Claim("Permission", role.Permission + ""));
                var additionalData = new AuthenticationProperties(new Dictionary <string, string> {
                    {
                        "role", Newtonsoft.Json.JsonConvert.SerializeObject(role.RoleName)
                    },
                    {
                        "userID", Newtonsoft.Json.JsonConvert.SerializeObject(role.UserID)
                    },
                    {
                        "permission", Newtonsoft.Json.JsonConvert.SerializeObject(role.Permission + "")
                    }
                });
                var token = new AuthenticationTicket(identity, additionalData);
                context.Validated(token);
            }
            else
            {
                return;
            }
        }
Example #2
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            UserDTO user = _userBUS.CheckLogin(txtID.Text, txtPassword.Text);

            if (user != null)
            {
                _ = new FrmHome(user, this)
                {
                    Visible = true
                };
                this.Hide();
            }
            else
            {
                MessageBox.Show("User Name or password not right!");
            }
        }
Example #3
0
 // Event btnLogin in loginform
 private void btnLogin_Click(object sender, EventArgs e)
 {
     // check conditition
     if ((!this.childForm.txtUser.Text.Split().Equals("")) &&
         (!this.childForm.txtPass.Text.Split().Equals("")))
     {
         //Call BUS
         UserBUS BUS = new UserBUS();
         // CheckLogin
         if (BUS.CheckLogin(this.childForm.txtUser.Text, this.childForm.txtPass.Text))
         {
             //Check ID
             int i = BUS.CheckLogID(this.childForm.txtUser.Text, this.childForm.txtPass.Text);
             //If  is admin
             if (i == 1)
             {
                 //start adminform
                 childForm5 = new FormAdmin(this.childForm.txtUser.Text);
                 // creat childform in parent
                 childForm5.MdiParent = this;
                 childForm5.Dock      = DockStyle.Fill;
                 childForm5.Show();
                 childForm5.btnBack.Click += BtnBack_Click;
             }
             else
             {
                 //start userform
                 childForm2 = new FormLogin(i, this.childForm.txtUser.Text);
                 // creat childform in parent
                 childForm2.MdiParent = this;
                 childForm2.Dock      = DockStyle.Fill;
                 childForm2.Show();
                 childForm2.btnBack.Click += BtnBack_Click;
             }
         }
         else
         {
             MessageBox.Show("Username or Password not correct!");
         }
     }
 }