Пример #1
0
        public ActionResult Add(Admin model)
        {
            var check = db.Admins.FirstOrDefault(u => u.email.ToLower().Equals(model.email.ToLower()));

            if (check != null)
            {
                return(Json(new { ok = false, mess = "Email này đã tồn tại" }, JsonRequestBehavior.AllowGet));
            }
            try
            {
                var passOld = StringClass.Encrypt("123456");
                passOld = StringClass.Encrypt(passOld);
                Admin data = new Admin();
                data.id        = Guid.NewGuid().ToString();
                data.fullName  = model.fullName;
                data.addresss  = model.addresss;
                data.phone     = model.phone;
                data.email     = model.email;
                data.active    = model.active;
                data.pass      = passOld;
                data.subAdmin  = false;
                data.dateStart = DateTime.Now;
                data.dateEnd   = DateTime.Now;
                data.keyFogot  = data.id;
                db.Admins.Add(data);
                db.SaveChanges();
                return(Json(new { ok = true, mess = "" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { ok = false, mess = "" }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
        public ActionResult UpdateFogotChange(LoginModel model)
        {
            var user = db.Admins.FirstOrDefault(u => u.keyFogot.Equals(model.SecurityKey));

            if (user == null)
            {
                return(Json(new { ok = false, mess = "Không tìm thấy yêu cầu lấy lại mật khẩu!" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var timeSp = DateTime.Now - user.dateStart.Value;
                if (timeSp.TotalMinutes >= 120)
                {
                    return(Json(new { ok = false, mess = "Yêu cầu lấy lại mật khẩu đã hết hạn!" }, JsonRequestBehavior.AllowGet));
                }
            }
            try
            {
                var passOld = StringClass.Encrypt(model.Password);
                passOld   = StringClass.Encrypt(passOld);
                user.pass = passOld;
                db.SaveChanges();
                return(Json(new { ok = true, mess = "" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { ok = false, mess = "" }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #3
0
        public ActionResult Register(string email, string password, string name, string tel, string address)
        {
            var cus    = db.Customers.Where(c => c.Email.Equals(email)).ToList();
            var result = "";

            if (cus.Count > 0)
            {
                result = "E-mail đã tồn tại..";
            }
            else
            {
                Customer customer = new Customer();
                customer.Email    = email;
                customer.Password = StringClass.Encrypt(password);
                customer.Name     = name;
                if (tel != null)
                {
                    customer.Tel = tel;
                }
                if (address != null)
                {
                    customer.Address = address;
                }
                customer.SDate = DateTime.Now;

                db.Entry(customer).State = System.Data.EntityState.Added;
                db.SaveChanges();

                Session["User-Email"] = email;
                result = "success";
            }

            return(Json(result));
        }
Пример #4
0
 protected void Update_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         DataAccess.User obj = new DataAccess.User();
         obj.Id       = Id;
         obj.Name     = txtName.Text;
         obj.Username = txtUsername.Text;
         obj.Level    = Level + "00000";
         obj.Admin    = txtAdmin.Text != "" ? txtAdmin.Text : "1";
         obj.Ord      = txtOrd.Text != "" ? txtOrd.Text : "1";
         obj.Active   = chkActive.Checked ? "1" : "0";
         if (Insert == true)
         {
             obj.Password = txtPassword.Text;
             UserService.User_Insert(obj);
         }
         else
         {
             obj.Password = txtPassword.Text != "" ? StringClass.Encrypt(txtPassword.Text) : Password;
             UserService.User_Update(obj);
         }
         BindGrid();
         pnView.Visible   = true;
         pnUpdate.Visible = false;
         Level            = "";
         Insert           = false;
     }
 }
Пример #5
0
        public ActionResult UpdatePass(LoginModel model)
        {
            var user = ClassExten.GetCokies();

            if (user == null)
            {
                return(Json(new { ok = 2, mess = "Phiên đăng nhập hết hạn, vui lòng đăng nhập lại để sử dụng tính năng" }, JsonRequestBehavior.AllowGet));
            }
            var data    = db.Admins.First(u => u.email.Equals(user.Email));
            var passOld = StringClass.Encrypt(model.Password);

            passOld = StringClass.Encrypt(passOld);
            if (!data.pass.Equals(passOld))
            {
                return(Json(new { ok = 0, mess = "Mật khẩu cũ không đúng" }, JsonRequestBehavior.AllowGet));
            }
            try
            {
                var passNew = StringClass.Encrypt(model.PasswordNew);
                passNew   = StringClass.Encrypt(passNew);
                data.pass = passNew;
                db.SaveChanges();
                return(Json(new { ok = 1, mess = "" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new { ok = 0, mess = "" }, JsonRequestBehavior.AllowGet));
            }
        }
        // [Authorize(Roles = "Admin")]  //Personnel
        public ActionResult Insert(string Taikhoan, string Matkhau, string Hoten, string Ngaysinh, string Gioitinh, string Diachi,
                                   string SDT, string Email, string Actice, string thutu)
        {
            Thanhvien_Model model = new Thanhvien_Model();//gọi model data

            model.Taikhoan = Taikhoan;
            if (Matkhau == "")
            {
                model.Matkhau = "";
            }
            else
            {
                model.Matkhau = StringClass.Encrypt(Matkhau);
            }
            model.Hoten    = Hoten;
            model.Ngaysinh = Convert.ToDateTime(Ngaysinh);

            if (Ngaysinh != "")
            {
                DateTime DateNgaysinh = DateTime.ParseExact(Ngaysinh, @"d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                model.Ngaysinh = DateNgaysinh;
            }
            else
            {
                model.Ngaysinh = null;
            }

            model.Gioitinh = Gioitinh;
            model.Diachi   = Diachi;
            model.SDT      = SDT;
            model.Email    = Email;
            model.Actice   = Convert.ToBoolean(Actice);
            model.thutu    = Convert.ToInt32(thutu);

            if (connect_entity.Thanhviens.FirstOrDefault
                    (x => x.Email == model.Email && x.Taikhoan == model.Taikhoan) == null) // kiểm tra không được trùng tên
            {
                Connect.Create(model);                                                     //gọi service lưu
                Resurt = 1;
            }
            else
            {
                Resurt = 0;
            }


            return(Json(Resurt, JsonRequestBehavior.AllowGet));
        }
        public bool Login(User_Model model)
        {
            string Name     = model.Username;
            string password = StringClass.Encrypt(model.Password);
            var    data     =
                Connect_Enttity.Users.FirstOrDefault(x => x.Username.Equals(Name) && x.Password.Equals(password) && x.Active == 1);

            if (data != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        protected void lbtUpdateB_Click(object sender, EventArgs e)
        {
            string PassEncode = StringClass.Encrypt(txtNewPassword.Text);

            #region [TestInput]
            if (txtCurrentPassword.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Current Password not null !");
                txtCurrentPassword.Focus();
                return;
            }
            if (txtCurrentPassword.Text != Session["Password"].ToString())
            {
                WebMsgBox.Show("Current Password error !");
                txtCurrentPassword.Focus();
                return;
            }
            if (txtNewPassword.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("New Password not null !");
                txtCurrentPassword.Focus();
                return;
            }
            if (txtReenterPassword.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Reenter Password not null  !");
                txtCurrentPassword.Focus();
                return;
            }
            if (txtNewPassword.Text != txtReenterPassword.Text)
            {
                WebMsgBox.Show("Password not same!");
                txtNewPassword.Focus();
                return;
            }
            #endregion

            try
            {
                AdminService.Admin_ChangePassword(Session["Username"].ToString(), PassEncode);
                WebMsgBox.Show("Change password success");
            }
            catch (Exception ex)
            {
                WebMsgBox.Show(ex.Message);
            }
        }
Пример #9
0
        public ActionResult Login(FormCollection fr)
        {
            try
            {
                LoginModel loginModel = new LoginModel();
                loginModel.Email    = fr["Username"];
                loginModel.Password = fr["password"];
                var pasHas = StringClass.Encrypt(loginModel.Password);
                pasHas = StringClass.Encrypt(pasHas);
                var userInfo = db.Admins.FirstOrDefault(u => u.email.ToLower().Equals(loginModel.Email.ToLower()) && u.pass.Equals(pasHas));
                if (userInfo != null)
                {
                    var securityKey = Guid.NewGuid().ToString();
                    loginModel.SecurityKey = securityKey;
                    var identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, userInfo.email),
                        new Claim(ClaimTypes.Actor, userInfo.fullName),
                        new Claim(ClaimTypes.Uri, string.Empty),
                        new Claim(ClaimTypes.Version, securityKey)
                    }, "ApplicationCookie");
                    var ctx         = Request.GetOwinContext();
                    var authManager = ctx.Authentication;
                    // authManager.SignIn(identity);
                    authManager.SignIn(new AuthenticationProperties {
                        IsPersistent = true, ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7)
                    }, identity);
                    loginModel.FullName = userInfo.fullName;
                    loginModel.subAdmin = userInfo.subAdmin.Value;
                    HttpCookie ntsCookies = new HttpCookie("adminNTS");
                    ntsCookies.Value   = JsonConvert.SerializeObject(loginModel);
                    ntsCookies.Expires = DateTime.Now.AddDays(7);
                    Response.Cookies.Add(ntsCookies);

                    return(Redirect("/Home/Index"));
                }
                else
                {
                    ViewBag.erro = "Tài khoản không hợp lệ";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewBag.erro = "Xảy ra lỗi vui lòng thử lại";
                return(View());
            }
        }
Пример #10
0
        public ActionResult Login(string email, string password)
        {
            var encryptPassword = StringClass.Encrypt(password);
            var cus             = db.Customers.Where(c => c.Email.Equals(email) && c.Password.Equals(encryptPassword)).ToList();

            if (cus.Count > 0)
            {
                Session["User-Email"] = email;
                Session["Name"]       = cus[0].Name;
                Session["uId"]        = cus[0].Id.ToString();
                var result = "success";
                return(Json(result));
            }
            else
            {
                var result = "E-mail hoặc Password không đúng, nhập lại..";
                return(Json(result));
            }
        }
        public void Update(User_Model model)
        {
            var data = Connect_Enttity.Users.FirstOrDefault(x => x.Id == model.Id);

            if (data != null)
            {
                data.Name     = model.Name;
                data.Username = model.Username;
                data.Password = StringClass.Encrypt(model.Password);
                data.Level    = model.Level;
                data.Admin    = model.Admin;
                data.Ord      = model.Ord;
                data.Active   = model.Active;
                data.Role     = model.Role;
                //  Connect_Enttity.Users.Attach(data);
                // Connect_Enttity.Entry(data).State = EntityState.Modified;
                Connect_Enttity.SaveChanges();
                Dispose();
            }
        }
Пример #12
0
 public ActionResult CustomerEditot(FormCollection collection, int id)
 {
     if (Request.Cookies["Username"] != null)
     {
         var cus = db.Customers.First(m => m.Id == id);
         cus.Name     = collection["Name"];
         cus.Email    = collection["Email"];
         cus.Password = StringClass.Encrypt(collection["Password"]);
         cus.Tel      = collection["Tel"];
         cus.Address  = collection["Address"];
         cus.SDate    = DateTime.Now;
         cus.Status   = (collection["Status"] == "false") ? false : true;
         db.SaveChanges();
         return(RedirectToAction("CustomerIndex"));
     }
     else
     {
         return(Redirect("/Admins/admins"));
     }
 }
        public void Create(User_Model model)
        {
            var data = Connect_Enttity.Users.FirstOrDefault(x => x.Id == model.Id);

            if (data == null)
            {
                var entity = new User();
                entity.Name     = model.Name;
                entity.Username = model.Username;
                entity.Password = StringClass.Encrypt(model.Password);
                entity.Level    = model.Level;
                entity.Admin    = model.Admin;
                entity.Ord      = model.Ord;
                entity.Active   = model.Active;
                entity.Role     = model.Role;

                Connect_Enttity.Users.Add(entity);
                Connect_Enttity.SaveChanges();
                Dispose();
            }
        }
Пример #14
0
 protected void btnLogon_Click(object sender, EventArgs e)
 {
     try
     {
         string passEncode = StringClass.Encrypt(txtPassword.Text);
         bool   resultAd   = AdminService.Admin_CheckLogin(txtUsername.Text, passEncode);
         if (resultAd)
         {
             Session["Username"] = txtUsername.Text;
             Session["Password"] = txtPassword.Text;
             Response.Redirect("Default.aspx");
         }
         else
         {
             ltrError.Text = "Logon fail";
         }
     }
     catch (Exception ex)
     {
         ltrError.Text = ex.Message;
     }
 }
 protected void Update_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         DataAccess.UsersInfo obj = new DataAccess.UsersInfo();
         obj.UserID   = Id;
         obj.FullName = txtName.Text;
         obj.UserName = txtUsername.Text;
         obj.Gender   = rdGender.SelectedValue;
         obj.Avatar   = txtAvatar.Text;
         obj.Birthday = cldBirthday.SelectedDate.ToString().Trim();
         //obj.Birthday = cldBirthday.SelectedDate;
         obj.Email       = txtEmail.Text;
         obj.Address     = txtAddress.Text;
         obj.MobilePhone = txtPhoneNumber.Text;
         obj.GroupID     = ddlGroupUser.SelectedValue;
         obj.Level       = ddlGroupUser.SelectedValue;
         obj.Admin       = txtAdmin.Text != "" ? txtAdmin.Text : "1";
         obj.Ord         = txtOrd.Text != "" ? txtOrd.Text : "1";
         obj.Active      = chkActive.Checked ? "1" : "0";
         if (Insert == true)
         {
             obj.Password = md5(txtPassword.Text);
             //UsersService.UsersInfo_Insert(obj);
         }
         else
         {
             obj.Password = md5(txtPassword.Text != "" ? StringClass.Encrypt(txtPassword.Text) : Password);
             UsersService.UsersInfo_Update(obj);
         }
         BindGrid();
         pnView.Visible   = true;
         pnUpdate.Visible = false;
         Level            = "";
         Insert           = false;
     }
 }
Пример #16
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     #region [TestInput]
     if (txtUsernameL.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Username not null !");
         txtUsernameL.Focus();
         return;
     }
     if (txtPasswordL.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Password not null !");
         txtUsernameL.Focus();
         return;
     }
     #endregion
     try
     {
         string passEncode = StringClass.Encrypt(txtPasswordL.Text);
         bool   resultAd   = CustomerService.Customer_CheckLogin(txtUsernameL.Text, passEncode);
         if (resultAd)
         {
             Session["User"] = txtUsernameL.Text;
             Session["Pass"] = txtPasswordL.Text;
             Response.Redirect("Default.aspx");
         }
         else
         {
             WebMsgBox.Show("Login fail");
         }
     }
     catch (Exception ex)
     {
         WebMsgBox.Show(ex.Message);
     }
 }
Пример #17
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string passEncode = StringClass.Encrypt(txtPassword.Text);
            #region[TestInput]
            if (txtCard.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Credit Card not null !");
                txtCard.Focus();
                return;
            }
            if (txtName.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Full Name not null !");
                txtName.Focus();
                return;
            }
            if (txtBirth.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Birth not null !");
                txtBirth.Focus();
                return;
            }
            if (txtAddress.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Address not null !");
                txtAddress.Focus();
                return;
            }
            if (txtPhone.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Phone not null !");
                txtPhone.Focus();
                return;
            }
            if (txtEmail.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Email  !");
                txtEmail.Focus();
                return;
            }
            if (!reg.IsMatch(txtEmail.Text))
            {
                WebMsgBox.Show("Not a valid email!");
                txtEmail.Focus();
                return;
            }
            #endregion

            try
            {
                var obj = new CustomerInfo();
                obj.CusId = txtId.Value;
                obj.Username = txtUsername.Text;
                obj.Password = passEncode;
                obj.CreditCard = txtCard.Text;
                obj.FullName = txtName.Text;
                obj.Bod = txtBirth.Text;
                obj.Address = txtAddress.Text;
                obj.Phone = txtPhone.Text;
                obj.Email = txtEmail.Text;
                obj.Avata = txtAvata.Text;
                obj.Status = chkActive.Checked ? "1" : "0";
                CustomerService.Customer_Update(obj);
                WebMsgBox.Show("Change information success");
                Information();
            }
            catch (Exception ex)
            {
                WebMsgBox.Show(ex.Message);
            }
        }
Пример #18
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string passEncode = StringClass.Encrypt(txtPassword.Text);

            #region [TestInput]
            if (txtUsername.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Username not null !");
                txtUsername.Focus();
                return;
            }
            if (txtPassword.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Password not null !");
                txtUsername.Focus();
                return;
            }
            if (txtReenterPassword.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Reenter Password not null !");
                txtUsername.Focus();
                return;
            }
            if (txtPassword.Text != txtReenterPassword.Text)
            {
                WebMsgBox.Show("Password not same !");
                txtUsername.Focus();
                return;
            }
            if (txtCard.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Credit Card not null !");
                txtCard.Focus();
                return;
            }
            if (txtName.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Full Name not null !");
                txtName.Focus();
                return;
            }
            if (txtBirth.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Birth not null !");
                txtBirth.Focus();
                return;
            }
            if (txtAddress.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Address not null !");
                txtAddress.Focus();
                return;
            }
            if (txtPhone.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Phone not null !");
                txtPhone.Focus();
                return;
            }
            if (txtEmail.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("Email  !");
                txtEmail.Focus();
                return;
            }
            if (!reg.IsMatch(txtEmail.Text))
            {
                WebMsgBox.Show("Not a valid email!");
                txtEmail.Focus();
                return;
            }
            #endregion

            try
            {
                var obj = new CustomerInfo();
                obj.Username   = txtUsername.Text;
                obj.Password   = passEncode;
                obj.CreditCard = txtCard.Text;
                obj.FullName   = txtName.Text;
                obj.Bod        = txtBirth.Text;
                obj.Address    = txtAddress.Text;
                obj.Phone      = txtPhone.Text;
                obj.Email      = txtEmail.Text;
                obj.Avata      = txtAvata.Text;
                obj.Status     = chkActive.Checked ? "1" : "0";
                CustomerService.Customer_Insert(obj);
                Response.Redirect("Login.aspx");
                txtUsername.Text = txtCard.Text = txtName.Text = txtAddress.Text = txtPhone.Text = txtEmail.Text = "";
            }
            catch (Exception ex)
            {
                WebMsgBox.Show(ex.Message);
            }
        }
Пример #19
0
 protected void lbtUpdateB_Click(object sender, EventArgs e)
 {
     #region [TestInput]
     if (txtUsername.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Username not null !");
         txtUsername.Focus();
         return;
     }
     if (txtPassword.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Password not null !");
         txtUsername.Focus();
         return;
     }
     if (txtCreditCard.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Credit Card not null !");
         txtCreditCard.Focus();
         return;
     }
     if (txtFullName.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Full Name not null !");
         txtFullName.Focus();
         return;
     }
     if (txtBod.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Birth not null !");
         txtBod.Focus();
         return;
     }
     if (txtAddress.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Address not null !");
         txtAddress.Focus();
         return;
     }
     if (txtPhone.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Phone not null !");
         txtPhone.Focus();
         return;
     }
     if (txtEmail.Text.Trim().Equals(""))
     {
         WebMsgBox.Show("Email  !");
         txtEmail.Focus();
         return;
     }
     if (!reg.IsMatch(txtEmail.Text))
     {
         WebMsgBox.Show("Not a valid email!");
         txtEmail.Focus();
         return;
     }
     #endregion
     string passEncode = StringClass.Encrypt(txtPassword.Text);
     try
     {
         var obj = new CustomerInfo();
         obj.CusId      = txtId.Value;
         obj.Username   = txtUsername.Text;
         obj.Password   = passEncode;
         obj.CreditCard = txtCreditCard.Text;
         obj.FullName   = txtFullName.Text;
         obj.Bod        = txtBod.Text;
         obj.Address    = txtAddress.Text;
         obj.Phone      = txtPhone.Text;
         obj.Email      = txtEmail.Text;
         obj.Avata      = txtAvata.Text;
         obj.Status     = chkActive.Checked ? "1" : "0";
         if (_insert == true)
         {
             CustomerService.Customer_Insert(obj);
         }
         else
         {
             CustomerService.Customer_Update(obj);
         }
         BindGrid();
         LoadFilterNewsNameAutocomplete();
         txtUsername.ReadOnly = true;
         pnView.Visible       = true;
         pnUpdate.Visible     = false;
         _insert = false;
     }
     catch (Exception ex)
     {
         WebMsgBox.Show(ex.Message);
     }
 }