예제 #1
0
        public IActionResult LogIn()
        {
            LoginViewModel user = new LoginViewModel();

            user.RememberMe = false;
            if (Request.Cookies[EncryptANDDecrypt.EncryptText("ECommerceUserName")] != null)
            {
                user.UserName = EncryptANDDecrypt.DecryptText(Request.Cookies[EncryptANDDecrypt.EncryptText("ECommerceUserName")]);
                user.Password = EncryptANDDecrypt.DecryptText(Request.Cookies[EncryptANDDecrypt.EncryptText("ECommercePassword")]);

                user.RememberMe = true;

                CookieOptions option = new CookieOptions {
                    Expires = DateTime.Now.AddDays(-1)
                };
                var currentUser = _uow.UsersRepository.GetMany(ent => ent.UserName == user.UserName && !ent.IsDeleted).FirstOrDefault();
                if (currentUser == null)
                {
                    return(View("Index"));
                }
                AppSession.CurrentUser = currentUser;
                var rqf = Request.HttpContext.Features.Get <IRequestCultureFeature>();
                return(RedirectToAction("Index", "Home"));
            }
            return(View(user));
        }
예제 #2
0
        public Users IsValidUser(string mobil, string password)
        {
            var user = _uow.UsersRepository.GetUsers().Where(ent => ent.Mobile.ToLower() == mobil.Trim() &&
                                                             ent.Password == EncryptANDDecrypt.EncryptText(password)).ToList();

            return(user.Count() == 1 ? user.FirstOrDefault() : null);
        }
예제 #3
0
 public IActionResult ChangePassword(ChangePassword password)
 {
     if (ModelState.IsValid)
     {
         var currentuser = AppSession.CurrentUser;
         if (currentuser == null)
         {
             return(RedirectToAction("LogIn", "Account"));
         }
         if (password != null && !string.IsNullOrEmpty(password.NewPassword) && password.NewPassword == password.ConfirmNewPassword)
         {
             if (password.CurrentPassword == password.NewPassword)
             {
                 ModelState.AddModelError("NewPassword", "New Password Must be Different from Current Password");
             }
             //current user password equal entered password
             if (EncryptANDDecrypt.DecryptText(currentuser.Password) != password.CurrentPassword)
             {
                 ModelState.AddModelError("CurrentPassword", "InCorrect Password!!");
             }
             if (ModelState.IsValid)
             {
                 currentuser.Password         = EncryptANDDecrypt.EncryptText(password.NewPassword);
                 currentuser.ModificationDate = DateTime.Now;
                 _uow.UsersRepository.Update(currentuser);
                 _uow.Save();
                 AppSession.CurrentUser = null;
                 return(RedirectToAction("ChangePasswordDone", "Account"));
             }
         }
     }
     return(View(password));
 }
        public IActionResult UpdateTechnicalProfile([FromBody] TechnicalProfileModel model)
        {
            var errors = new List <string>();

            try
            {
                #region Save Technical

                var technical = _uow.UsersRepository.GetMany(ent => ent.Id == model.Id).Include(ent => ent.Technical).FirstOrDefault();
                if (technical == null || technical.Technical == null)
                {
                    errors.Add("Technical with Id: " + model.Id + " not found");
                }
                if (errors.Count == 0)
                {
                    technical.ArabicName       = technical.EnglishName = model.Name;
                    technical.UserName         = model.UserName;
                    technical.Mobile           = model.Mobile;
                    technical.Password         = EncryptANDDecrypt.EncryptText(model.Password);
                    technical.ModificationDate = DateTime.Now;
                    technical.Location         = model.Location;
                    var validatetechnerrors = validatetechnical(technical);
                    if (validatetechnerrors == null || validatetechnerrors.Count() == 0)
                    {
                        _uow.UsersRepository.Update(technical);
                        _uow.Save();
                        return(Ok(new ApiResponseModel
                        {
                            Status = EN_ResponseStatus.Success,
                            Message = "Record Saved Successfully",
                            Data = null,
                            Errors = null
                        }));
                    }
                    else
                    {
                        errors.AddRange(validatetechnerrors);
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                errors.Add("Error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    errors.Add(ex.InnerException.Message);
                }
            }
            return(Ok(new ApiResponseModel
            {
                Status = EN_ResponseStatus.Faild,
                Message = "Error Occured",
                Data = null,
                Errors = errors.ToArray()
            }));
        }
        public IActionResult CustomerChangePassword([FromBody] ChangePassword password, long CurrentCustId)
        {
            if (ModelState.IsValid)
            {
                var currentcust = _uow.CustomerRepository.Get(ent => ent.Id == CurrentCustId);
                if (currentcust == null)
                {
                    ModelState.AddModelError("", "Customer with Id :" + CurrentCustId + " Can't be found");
                }
                else if (password != null && !string.IsNullOrEmpty(password.NewPassword) && password.NewPassword == password.ConfirmNewPassword)
                {
                    if (password.CurrentPassword == password.NewPassword)
                    {
                        ModelState.AddModelError("NewPassword", "New Password Must be Different from Current Password");
                    }
                    //current user password equal entered password
                    if (EncryptANDDecrypt.DecryptText(currentcust.Password) != password.CurrentPassword)
                    {
                        ModelState.AddModelError("CurrentPassword", "InCorrect Password!!");
                    }
                    if (ModelState.IsValid)
                    {
                        currentcust.Password         = EncryptANDDecrypt.EncryptText(password.NewPassword);
                        currentcust.ModificationDate = DateTime.Now;
                        _uow.CustomerRepository.Update(currentcust);
                        _uow.Save();
                        return(Ok(new ApiResponseModel
                        {
                            Status = EN_ResponseStatus.Success,
                            Message = "Change Password Done",
                            Data = null,
                            Errors = null
                        }));
                    }
                }
            }
            var errors      = ModelState.Select(ent => new { key = ent.Key, value = ent.Value.Errors.Select(err => (err.ErrorMessage == null || err.ErrorMessage == "") ? err.Exception.Message : err.ErrorMessage) });
            var errors_list = new List <string>();

            foreach (var sublist in errors)
            {
                foreach (var item in sublist.value)
                {
                    errors_list.Add(sublist.key + ": " + item);
                }
            }
            return(Ok(new ApiResponseModel
            {
                Status = EN_ResponseStatus.Faild,
                Message = "Error Occured",
                Data = null,
                Errors = errors_list.ToArray()
            }));
        }
예제 #6
0
        public static bool AuthenticateCustomer(LoginViewModel user, ISecurity sec, IUnitOfWork uow)
        {
            bool isValid = false;

            if (!isValid)
            {
                string encPassword = EncryptANDDecrypt.EncryptText(user.Password);
                var    result      = uow.CustomerRepository.GetMany(ent => ent.Email.ToLower() == user.UserName.ToLower() && ent.Password == encPassword && !ent.IsDeleted && ent.IsActive).ToHashSet();
                isValid = result.Count() == 1;
            }
            return(isValid);
        }
예제 #7
0
 public IActionResult LogIn(LoginViewModel model)
 {
     if (ModelState.IsValid)
     {
         CookieOptions option = new CookieOptions {
             Expires = DateTime.Now.AddDays(-1)
         };
         if (model.RememberMe)
         {
             option.Expires = DateTime.Now.AddDays(30);
         }
         Response.Cookies.Append(EncryptANDDecrypt.EncryptText("ECommerceUserName"), EncryptANDDecrypt.EncryptText(model.UserName), option);
         Response.Cookies.Append(EncryptANDDecrypt.EncryptText("ECommercePassword"), EncryptANDDecrypt.EncryptText(model.Password), option);
         var user = _uow.UsersRepository.GetMany(ent => ent.UserName == model.UserName && !ent.IsDeleted).FirstOrDefault();
         if (user == null)
         {
             ModelState.AddModelError("", "UserNotFoundErrMsg");
             ViewBag.ErrorMessage = "User Not Found ";
             return(View(model));
         }
         else if (!user.IsActive)
         {
             ModelState.AddModelError("", "UserIsInActiveErrMsg");
             ViewBag.ErrorMessage = "User Is InActive";
             return(View(model));
         }
         else if (!UserAccountMannager.AuthenticateUser(model, _Security, _uow))
         {
             ModelState.AddModelError("", "UserOrPasswordIsWrongErrMsg");
             ViewBag.ErrorMessage = "User Or Password Is WrongErrMsg";
             return(View(model));
         }
         else
         {
             AppSession.CurrentUser = user;
             var rqf = Request.HttpContext.Features.Get <IRequestCultureFeature>();
             return(RedirectToAction("Index", "Home"));
         }
     }
     return(View(model));
 }
        public IActionResult Save(Customer entity)
        {
            string strReturnMsg = "error";

            try
            {
                entity.Password = EncryptANDDecrypt.EncryptText(entity.Password);
                if (entity.Id == default)
                {
                    entity.Code         = UIHelper.GeneratCode(EN_Screens.Customer, _uow);
                    entity.CreationDate = DateTime.Now;
                    entity.CreatedBy    = AppSession.CurrentUser.Id;
                    //Re-ValidateModel
                    ModelState.Clear();
                    TryValidateModel(entity);
                    //UploadedFile(entity, form);
                    if (ModelState.IsValid)
                    {
                        _uow.CustomerRepository.Add(entity);
                    }
                }
                else
                {
                    entity.ModificationDate = DateTime.Now;
                    entity.ModifiedBy       = AppSession.CurrentUser.Id;
                    //Re-ValidateModel
                    ModelState.Clear();
                    TryValidateModel(entity);
                    if (ModelState.IsValid)
                    {
                        _uow.CustomerRepository.Update(entity);
                    }
                }
                _uow.Save();
                strReturnMsg = "success";
            }
            catch (Exception ex)
            { }
            return(Json(new { id = entity.Id, status = strReturnMsg }));
        }
예제 #9
0
        public IActionResult Save(Users entity, IFormCollection form)
        {
            string strReturnMsg = "error";
            var    technical    = entity.Technical;

            entity.Technical = null;

            ///revalidate
            ModelState.Clear();

            if (!TryValidateModel(entity))
            {
                return(View());
            }
            else
            {
                try
                {
                    entity.Password = EncryptANDDecrypt.EncryptText(entity.Password);
                    if (entity.Id == default)
                    {
                        entity.Code         = UIHelper.GeneratCode(EN_Screens.Users, _uow);
                        entity.CreationDate = DateTime.Now;
                        entity.CreatedBy    = AppSession.CurrentUser.Id;
                        _uow.UsersRepository.Add(entity);

                        if (entity.JobTitleId == (int)En_JobTitle.Technical)
                        {
                            technical.UsersId = entity.Id;
                            _uow.TechnicalsRepository.Add(technical);
                        }
                    }
                    else
                    {
                        if (!entity.IsMaster)
                        {
                            entity.ModificationDate = DateTime.Now;
                            entity.ModifiedBy       = AppSession.CurrentUser.Id;
                            _uow.UsersRepository.Update(entity);
                            if (entity.JobTitleId == (int)En_JobTitle.Technical)
                            {
                                technical.UsersId = entity.Id;
                                _uow.TechnicalsRepository.Update(technical);
                            }
                        }
                    }
                    _uow.Save();
                    #region Save groups
                    if (!entity.IsMaster)
                    {
                        string g = form["Groups"];
                        if (!string.IsNullOrEmpty(form["Groups"]))
                        {
                            var selectedGroups = form["Groups"].ToString().Split(",").Select(ent => long.Parse(ent)).ToHashSet();
                            foreach (var selectedGroupId in selectedGroups)
                            {
                                var dbObj = _uow.UserGroupsRepository.Get(ent => ent.GroupId == selectedGroupId && ent.UserId == entity.Id);
                                if (dbObj == null)
                                {
                                    var obj = new UserGroups();
                                    obj.UserId  = entity.Id;
                                    obj.GroupId = selectedGroupId;
                                    _uow.UserGroupsRepository.Add(obj);
                                }
                            }

                            var deletedUserGroups = _uow.UserGroupsRepository.GetMany(ent => ent.UserId == entity.Id && !selectedGroups.Contains(ent.GroupId)).Select(ent => ent.Id).ToHashSet();
                            if (deletedUserGroups.Count() > 0)
                            {
                                _uow.ExecuteSqlCommand("DELETE FROM UserGroups WHERE Id IN(" + string.Join(",", deletedUserGroups) + ")");
                            }
                            _uow.Save();
                        }
                        else
                        {
                            _uow.ExecuteSqlCommand("DELETE FROM UserGroups WHERE UserId=" + entity.Id);
                        }
                    }
                    #endregion
                    strReturnMsg = "success";
                }
                catch (Exception ex)
                { }
            }

            return(Json(new { id = entity.Id, status = strReturnMsg }));
        }
예제 #10
0
        public Customer IsValidCustomer(string email, string password)
        {
            var user = _uow.CustomerRepository.GetMany(ent => (ent.Email.ToLower() == email.ToLower().Trim() ||
                                                               ent.Mobile.ToLower() == email.ToLower().Trim()) && ent.Password == EncryptANDDecrypt.EncryptText(password) &&
                                                       !ent.IsDeleted && ent.IsActive
                                                       ).ToList();

            return(user.Count() == 1 ? user.FirstOrDefault() : null);
        }
        public IActionResult Register([FromBody] SignUpModelForAPI model)
        {
            var errors = new List <string>();

            try
            {
                #region Save Customer
                var obj = new Customer();
                if (model == null)
                {
                    errors.Add("Customer Data Can't be null");
                }
                else
                {
                    obj.Code         = UIHelper.GeneratCode(EN_Screens.Customer, _uow);
                    obj.UserName     = model.UserName;
                    obj.Email        = model.Email;
                    obj.Password     = EncryptANDDecrypt.EncryptText(model.Password);
                    obj.ArabicName   = obj.EnglishName = model.Name;
                    obj.Mobile       = model.Mobile;
                    obj.Address      = model.Address;
                    obj.ImageName    = AppSession.CustomerDefaultImage;
                    obj.CreationDate = DateTime.Now;
                    var validatecusterrors = validatecustomer(obj);
                    if (validatecusterrors == null || validatecusterrors.Count() == 0)
                    {
                        _uow.CustomerRepository.Add(obj);
                        _uow.Save();
                        var data = new
                        {
                            Id   = obj.Id,
                            Name = obj.ArabicName,
                            obj.Email,
                            obj.UserName,
                            obj.Mobile,
                            obj.Pocket,
                            obj.Address,
                            Image = AppSession.AppURL + AppSession.CustomerUploads + "/" + obj.ImageName,
                            token = ""
                        };
                        return(Ok(new ApiResponseModel
                        {
                            Status = EN_ResponseStatus.Success,
                            Message = "Record Saved Successfully",
                            Data = data,
                            Errors = null
                        }));
                    }
                    else
                    {
                        errors.AddRange(validatecusterrors);
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                errors.Add("Error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    errors.Add(ex.InnerException.Message);
                }
            }
            return(Ok(new ApiResponseModel
            {
                Status = EN_ResponseStatus.Faild,
                Message = "Error Occured",
                Data = null,
                Errors = errors.ToArray()
            }));
        }
        public IActionResult UpdateCustomerProfile([FromBody] CustomerProfileModel model)
        {
            var errors = new List <string>();

            try
            {
                #region Save Customer

                var obj  = _uow.CustomerRepository.Get(ent => ent.Id == model.Id);
                var city = _uow.CityRepository.Get(ent => ent.Id == model.CityId);

                if (obj == null)
                {
                    errors.Add("Customer with Id: " + model.Id + " not found");
                }
                if (city == null && model.CityId != 0)
                {
                    errors.Add("City with Id: " + model.CityId + " not found");
                }
                if (errors.Count == 0)
                {
                    obj.ArabicName       = obj.EnglishName = model.Name;
                    obj.Email            = model.Email;
                    obj.UserName         = model.UserName;
                    obj.Mobile           = model.Mobile;
                    obj.Password         = EncryptANDDecrypt.EncryptText(model.Password);
                    obj.ModificationDate = DateTime.Now;
                    obj.Address          = model.Address;
                    obj.CityId           = model.CityId;
                    var validatecusterrors = validatecustomer(obj);
                    if (validatecusterrors == null || validatecusterrors.Count() == 0)
                    {
                        _uow.CustomerRepository.Update(obj);
                        _uow.Save();

                        #endregion
                        return(Ok(new ApiResponseModel
                        {
                            Status = EN_ResponseStatus.Success,
                            Message = "Record Saved Successfully",
                            Data = null,
                            Errors = null
                        }));
                    }
                    else
                    {
                        errors.AddRange(validatecusterrors);
                    }
                }
            }
            catch (Exception ex)
            {
                errors.Add("Error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    errors.Add(ex.InnerException.Message);
                }
            }
            return(Ok(new ApiResponseModel
            {
                Status = EN_ResponseStatus.Faild,
                Message = "Error Occured",
                Data = null,
                Errors = errors.ToArray()
            }));
        }