Exemplo n.º 1
0
 public ActionResult CreateUser(RegisterViewModel register)
 {
     if (!ModelState.IsValid)
     {
         return(View(register));
     }
     if (!_iUser.IsMobileNumberExist(register.Mobile))
     {
         TblUsers users1 = new TblUsers();
         users1.IsActive = true;
         users1.Mobile   = register.Mobile;
         users1.Name     = register.Name;
         users1.Code     = CodeGenerators.ActiveCode();
         users1.Password = HashGenerators.EncodingPassWithMd5(register.Password);
         users1.RoleId   = 1;
         TblUsers user = users1;
         this._iUser.AddUser(user);
         return(base.RedirectToAction("Index"));
     }
     else
     {
         ModelState.AddModelError("Mobile", "شما قبلا ثبت نام کرده اید");
         return(View(register));
     }
 }
Exemplo n.º 2
0
        public bool ResetPassword(string activeCode, string password)
        {
            var TblUsers = _context.TblUsers.FirstOrDefault(u => u.Code == activeCode && u.IsActive == true);

            if (TblUsers != null)
            {
                string hashpassword = HashGenerators.EncodingPassWithMd5(password);
                TblUsers.Password = hashpassword;
                TblUsers.Code     = CodeGenerators.ActiveCode();
                _context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public bool ResetPassword(string code, string password)
        {
            User user = _context.Users.FirstOrDefault(u => u.ActiveCode == code);

            if (user != null)
            {
                user.Password   = HashGenerators.MD5Encoding(password);
                user.ActiveCode = CodeGenerators.ActiveCode();
                _context.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public bool ChangePassword(string mobileNumber, string currentPassword, string password)
        {
            string HashCurrentPass = HashGenerators.EncodingPassWithMd5(currentPassword);

            var TblUsers = _context.TblUsers.FirstOrDefault(u => u.Mobile == mobileNumber && u.Password == HashCurrentPass);

            if (TblUsers != null)
            {
                string HashNewPass = HashGenerators.EncodingPassWithMd5(password);
                TblUsers.Password = HashNewPass;

                _context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        public IActionResult Register(RegisterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_account.ExistsMobileNumber(viewModel.Mobile))
                {
                    // Go To Login
                }
                else
                {
                    User user = new User()
                    {
                        Mobile     = viewModel.Mobile,
                        ActiveCode = CodeGenerators.ActiveCode(),
                        Code       = null,
                        Date       = pc.GetYear(DateTime.Now).ToString("0000") + "/" + pc.GetMonth(DateTime.Now).ToString("00") +
                                     "/" + pc.GetDayOfMonth(DateTime.Now).ToString("00"),
                        FullName = null,
                        IsActive = false,
                        Password = HashGenerators.MD5Encoding(viewModel.Password),
                        RoleId   = _account.GetMaxRole()
                    };

                    _account.AddUser(user);

                    try
                    {
                        MessageSender sender = new MessageSender();

                        sender.SMS(viewModel.Mobile, "به فروشگاه اینترنتی خوش آمدید" + Environment.NewLine + "کد فعالسازی : " + user.ActiveCode);
                    }
                    catch
                    {
                    }

                    return(RedirectToAction(nameof(Activate)));
                }
            }

            return(View(viewModel));
        }
Exemplo n.º 6
0
 public ActionResult Edit(int id, EditUserViewModel tblUsers)
 {
     if (base.ModelState.IsValid)
     {
         string password = tblUsers.Password;
         tblUsers.Password = HashGenerators.EncodingPassWithMd5(password);
         TblUsers users = new TblUsers
         {
             Id       = tblUsers.Id,
             Mobile   = tblUsers.Mobile,
             Name     = tblUsers.Name,
             Password = tblUsers.Password
         };
         if (_iAdmin.UpdateUser(users))
         {
             return(base.RedirectToAction("Index"));
         }
         tblUsers.Password = password;
     }
     return(View(tblUsers));
 }
Exemplo n.º 7
0
        public IActionResult Store(StoreRegisterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_account.ExistsMailAddress(viewModel.Mail))
                {
                    ViewBag.MyMessage = false;
                    ModelState.AddModelError("Mail", "نمی توانید از این ایمیل استفاده کنید");
                }
                else
                {
                    int    userID     = 0;
                    string mobileCode = "";

                    if (_account.ExistsMobileNumber(viewModel.Mobile))
                    {
                        _account.UpdateUserRole(viewModel.Mobile);

                        userID = _account.GetUserId(viewModel.Mobile);

                        mobileCode = _account.GetUserActiveCode(viewModel.Mobile);
                    }
                    else
                    {
                        mobileCode = CodeGenerators.ActiveCode();

                        User user = new User()
                        {
                            ActiveCode = mobileCode,
                            Code       = null,
                            FullName   = null,
                            IsActive   = false,
                            Mobile     = viewModel.Mobile,
                            Password   = HashGenerators.MD5Encoding(viewModel.Password),
                            Date       = pc.GetYear(DateTime.Now).ToString("0000") + "/" + pc.GetMonth(DateTime.Now).ToString("00") +
                                         "/" + pc.GetDayOfMonth(DateTime.Now).ToString("00"),
                            RoleId = _account.GetStoreRole()
                        };

                        _account.AddUser(user);

                        userID = user.Id;
                    }

                    Store store = new Store()
                    {
                        Address          = null,
                        Desc             = null,
                        Logo             = null,
                        Mail             = viewModel.Mail,
                        MailActivate     = false,
                        MobileActivate   = false,
                        Tel              = null,
                        UserId           = userID,
                        Name             = null,
                        MailActivateCode = CodeGenerators.ActiveCode()
                    };

                    _account.AddStore(store);

                    ViewBag.MyMessage = true;

                    MessageSender sender = new MessageSender();

                    string messageBody = _render.RenderToStringAsync("_ActivateMail", store);

                    try
                    {
                        sender.Email(store.Mail, "فعالسازی فروشگاه", messageBody);
                        //sender.SMS(viewModel.Mobile, "درخواست ثبت فروشگاه انجام شد" + Environment.NewLine + "کد فعالسازی : " + mobileCode);
                    }
                    catch
                    {
                    }
                }
            }

            return(View(viewModel));
        }
Exemplo n.º 8
0
        public IActionResult Login(LoginViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                string hashPassword = HashGenerators.MD5Encoding(viewModel.Password);

                User user = _account.LoginUser(viewModel.Mobile, hashPassword);

                if (user != null)
                {
                    if (user.Role.Name == "فروشگاه")
                    {
                        var claims = new List <Claim>()
                        {
                            new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                            new Claim(ClaimTypes.Name, user.Mobile)
                        };

                        var identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                        var principal = new ClaimsPrincipal(identity);

                        var properties = new AuthenticationProperties()
                        {
                            IsPersistent = true
                        };

                        HttpContext.SignInAsync(principal, properties);

                        return(RedirectToAction("Dashboard", "Panel"));
                    }
                    else
                    {
                        if (user.IsActive)
                        {
                            var claims = new List <Claim>()
                            {
                                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                                new Claim(ClaimTypes.Name, user.Mobile)
                            };

                            var identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                            var principal = new ClaimsPrincipal(identity);

                            var properties = new AuthenticationProperties()
                            {
                                IsPersistent = true
                            };

                            HttpContext.SignInAsync(principal, properties);

                            if (user.Role.Name == "کاربر")
                            {
                                return(RedirectToAction("Dashboard", "Home"));
                            }
                            else
                            {
                                return(RedirectToAction("Dashboard", "Panel"));
                            }
                        }
                        else
                        {
                            return(RedirectToAction(nameof(Activate)));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("Password", "مشخصات کاربری اشتباه است");
                }
            }

            return(View(viewModel));
        }
Exemplo n.º 9
0
        public TblUsers LoginUser(string mobileNumber, string password)
        {
            string HashPassword = HashGenerators.EncodingPassWithMd5(password);

            return(_context.TblUsers.FirstOrDefault(u => u.Mobile == mobileNumber && u.Password == HashPassword));
        }