Exemplo n.º 1
0
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                Users user = UsersCrud.Login(model.Email, model.Password);

                if (user != null)
                {
                    //await Authenticate(user); // аутентификация
                    ClaimsIdentity identity = GetIdentity(model.Email, model.Password);

                    var now = DateTime.UtcNow;
                    // создаем JWT-токен
                    var jwt = new JwtSecurityToken(
                        issuer: AuthOptions.ISSUER,
                        audience: AuthOptions.AUDIENCE,
                        notBefore: now,
                        claims: identity.Claims,
                        expires: now.AddMinutes(1),
                        signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256));
                    var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);

                    HttpContext.Response.Cookies.Append(AuthOptions.CookiesName, encodedJwt.ToString(),
                                                        new CookieOptions
                    {
                        MaxAge = TimeSpan.FromMinutes(1)
                    });

                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("", "Некорректные логин и(или) пароль");
            }
            return(View(model));
        }
Exemplo n.º 2
0
 private void RegisterUserForm_Load(object sender, EventArgs e)
 {
     if (isForUpdate == true)
     {
         btnUpdate.Enabled   = true;
         btnRegister.Enabled = false;
         UsersCrud usersCrud = new UsersCrud();
         var       user      = usersCrud.findUserByID(userID);
         txtName.Text        = user.name;
         txtFamily.Text      = user.family;
         txtUserCode.Text    = user.userCode;
         txtUserName.Text    = user.userName;
         txtUserName.Enabled = false;
         txtPassword.Text    = user.password;
     }
 }
Exemplo n.º 3
0
        private void btnDeleteUser_Click(object sender, EventArgs e)
        {
            var currentRow = grdUsers.CurrentRow;

            if (currentRow != null)
            {
                int ID          = Int32.Parse(currentRow.Cells[0].Value.ToString());
                var userService = new UsersCrud();
                userService.DisableUser(ID);
                MessageBox.Show("عملیات با موفقیت انجام شد");
            }
            else
            {
                MessageBox.Show("لطفا رکورد مورد نظر خود را انتخاب نمایید.");
            }
        }
Exemplo n.º 4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var userContext = new UsersCrud();

            if (userContext.CheckProgramIsActive() == false)
            {
                MessageBox.Show("برنامه قفل می باشد، لطفا برای فعال سازی برنامه کد خریداری شده را وارد نمایید.");
                button1.Enabled = true;
                return;
            }
            var userName = txtUser.Text;
            var password = txtPassword.Text;

            if (userName == "" ||
                password == "")
            {
                MessageBox.Show("نام کاربر یا کلمه عبور وارد نشده است", "ورود", MessageBoxButtons.OK);
                return;
            }

            var user = userContext.findUser(userName, CommonUtils.HashingPassword(password));

            if (user != null)
            {
                if (user.IsActive == 1)
                {
                    UserLogged.UserID       = user.ID;
                    UserLogged.UserName     = user.userName;
                    CommonUtils.uniqeUserID = user.ID.ToString();
                    RegisterUserForm frmUser = new RegisterUserForm();
                    frmUser.Show();
                    this.Hide();
                    return;
                }
                else
                {
                    MessageBox.Show("نام کاربر یا کلمه عبور اشتباه است", "ورود", MessageBoxButtons.OK);
                    return;
                }
            }
            else
            {
                MessageBox.Show("نام کاربر یا کلمه عبور اشتباه است", "ورود", MessageBoxButtons.OK);
                return;
            }
        }
Exemplo n.º 5
0
        private void searchGrid()
        {
            var Name        = txtName.Text;
            var Family      = txtFamily.Text;
            var UserName    = txtUserName.Text;
            var userService = new UsersCrud();
            var data        = userService.findUsers(Name, Family, UserName);

            grdUsers.DataSource              = data;
            grdUsers.Columns[0].HeaderText   = "شناسه کاربر";
            grdUsers.Columns[1].HeaderText   = "نام";
            grdUsers.Columns[2].HeaderText   = "نام خانوادگی";
            grdUsers.Columns[3].HeaderText   = "کد کاربر";
            grdUsers.Columns[4].HeaderText   = "نام کاربری";
            grdUsers.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            grdUsers.Columns[5].Visible      = false;
        }
Exemplo n.º 6
0
        private void DraftRegister_Load(object sender, EventArgs e)
        {
            UsersCrud  usersCrud  = new UsersCrud();
            UniqueCrud uniqueCrud = new UniqueCrud();

            uniqueModel = uniqueCrud.GetLastUnique();
            var users = usersCrud.findUsers();

            txtUserID.DisplayMember = "Name";
            txtUserID.ValueMember   = "ID";

            txtDate.Text = CommonUtils.ConvertMiladiToPersianDate(DateTime.Now.ToShortDateString());
            foreach (var item in users)
            {
                var model = new ItemModel();
                model.Name = item.name + " " + item.family;
                model.ID   = item.ID;
                txtUserID.Items.Add(model);
            }

            txtTruck.DisplayMember = "Name";
            txtTruck.ValueMember   = "ID";
            foreach (var item in CommonUtils.getTrucksType())
            {
                txtTruck.Items.Add(item);
            }

            if (isForUpdate == true)
            {
                btnUpdate.Enabled   = true;
                btnRegister.Enabled = false;
                DraftCrud draftCrud = new DraftCrud();
                var       draft     = draftCrud.findDraftByID(DraftID);
                setElementsValue(draft);
            }



            if (isForUpdate == false)
            {
                fillForRegisterLoad();
            }
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            DbContext db         = new DbContext();
            UsersCrud usersCrud  = new UsersCrud();
            var       lstSecrets = usersCrud.GetAllSecretCodes();

            if (lstSecrets.Any(r => r.Key == txtSecret.Text))
            {
                var itemSecret = lstSecrets.Where(z => z.Key == txtSecret.Text).FirstOrDefault();
                int Year       = CommonUtils.ConvertMiladiToPersianDateGetYear(DateTime.Now.ToString());

                if (Int32.Parse(itemSecret.FromDate) == Year)
                {
                    if (itemSecret.IsActive == 0)
                    {
                        if (db.ActiveSecretCode(txtSecret.Text) == true)
                        {
                            MessageBox.Show("فعال سازی برای سال جاری با موفقیت انجام گردید.");
                            isActive = true;
                            this.Close();
                        }
                        ;
                    }
                    else
                    {
                        MessageBox.Show("کد وارد شده قبلا وارد شده و فعال گردیده است");
                        isActive = true;
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("کد فعال سازی صحیح نمی باشد.");
                    return;
                }
            }
            else
            {
                MessageBox.Show("کد فعال سازی صحیح نمی باشد.");
                return;
            }
        }
Exemplo n.º 8
0
        private ClaimsIdentity GetIdentity(string username, string password)
        {
            Users user = UsersCrud.Login(username, password);

            if (user != null)
            {
                List <Claim> claims = new List <Claim>
                {
                    new Claim(ClaimsIdentity.DefaultNameClaimType, user.email),
                    new Claim("UserFio", user.userFio),
                    new Claim(ClaimsIdentity.DefaultRoleClaimType, user.role)
                };

                ClaimsIdentity claimsIdentity =
                    new ClaimsIdentity(claims, JwtBearerDefaults.AuthenticationScheme, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
                claimsIdentity.Label = user.userFio;
                return(claimsIdentity);
            }

            return(null);
        }
Exemplo n.º 9
0
        private bool VerifyUser(string userName, string password)
        {
            string error  = string.Empty;
            bool   result = false;
            Users  oUsers = new UsersCrud().GetUserBy(OwnerApp + "/" + userName);

            if (oUsers == null)
            {
                error            = "User name is wrong !!, Please corect";
                txtUserName.Text = "";
                txtUserName.Focus();
                result = false;
            }
            else
            {
                string pass = new UsersCrud().GetUserVerifyPassword(password);
                //kesamaan password
                if (oUsers.Passwords.Equals(pass))
                {
                    DataTable dtRole = new RoleUserCrud().GetRoleUserBy(OwnerApp + "/" + userName);
                    Session[Constants.USERID]   = dtRole.Rows[0]["USERID"].ToString();
                    Session[Constants.USERNAME] = dtRole.Rows[0]["USERNAME"].ToString();
                    Session[Constants.ROLEID]   = dtRole.Rows[0]["ROLEID"].ToString();
                    Session[Constants.ROLENAME] = dtRole.Rows[0]["ROLENAME"].ToString();
                    result = true;
                }
                else
                {
                    error            = "Password is wrong !!, Please corect";
                    txtPassword.Text = "";
                    txtPassword.Focus();
                    result = false;
                }
            }
            string script = string.Format("alert('{0}')", error);

            ScriptManager.RegisterStartupScript(this, typeof(string), "onClick", script, true);
            return(result);
        }
Exemplo n.º 10
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = @"C:\";
            openFileDialog.Title            = "بارگزاری نسخه دیتابیس";
            openFileDialog.Filter           = "Database File (*.db)|*.db";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string path      = openFileDialog.FileName;
                var    resultMsg = MessageBox.Show("آیا میخواهید عملیات بارگزاری انجام شود?", "بارگزارش", MessageBoxButtons.YesNo);
                if (resultMsg == DialogResult.Yes)
                {
                    DraftCrud draftCrud    = new DraftCrud();
                    var       draftRecords = draftCrud.GetDrafts(path);
                    draftCrud.saveIntoDraftTable(draftRecords);
                    draftCrud.UpdateDraftTabe(path);
                    UsersCrud usersCrud   = new UsersCrud();
                    var       userRecords = usersCrud.GetUsers(path);
                    usersCrud.saveIntoDraftTable(userRecords);
                    MessageBox.Show("عملیات بارگذاری با موفقیت تکمیل گردید.");
                }
            }
        }
Exemplo n.º 11
0
 public void Del(int Id)
 {
     UsersCrud.Del(Id);
 }
Exemplo n.º 12
0
 public void Edit(Users model)
 {
     UsersCrud.Edit(model);
 }
Exemplo n.º 13
0
 public JsonResult Add(Users model)
 {
     model = UsersCrud.Add(model);
     return(Json(model));
 }
Exemplo n.º 14
0
        public JsonResult GetData()
        {
            List <Users> list = UsersCrud.GetAll();

            return(Json(list));
        }