Пример #1
0
        public IActionResult Update_old([FromBody] dto_Settings settings)
        {
            GenericResponse _res = new GenericResponse();

            _res.FillSuccess();
            if (settings != null)
            {
                if (ModelState.IsValid)
                {
                    dto_Settings _old = _service_Settings.Get(settings.ID);
                    _old.Conf_Value = settings.Conf_Value;
                    _service_Settings.update(_old);
                }
                else
                {
                    _res.FillError("model state is invalid");
                    _log.Error("model state is invalid");
                }
            }
            else
            {
                _res.FillError("setting is null");
                _log.Error("setting is null");
            }
            return(Ok(_res));
        }
Пример #2
0
        public IActionResult ForgotPassword([FromBody] dto_User model)
        {
            GenericResponse res = new GenericResponse();

            res.FillSuccess();
            if (model != null && !string.IsNullOrEmpty(model.Email))
            {
                var olduser = _service_account.GetUser(model.Email);
                if (olduser != null)
                {
                    _emailHelper.AddToAddress(model.Email);
                    _emailHelper.Subject = "Reset Password";
                    _emailHelper.Body    = "Kindly find your password as following : " + olduser.Password;
                    _emailHelper.SendMail();
                }
                else
                {
                    res.FillError();
                }
            }
            else
            {
                res.FillError();
            }



            return(Ok(res));
        }
Пример #3
0
        public IActionResult Update([FromBody] dto_GridSettings settings)
        {
            GenericResponse _res = new GenericResponse();

            _res.FillSuccess();
            if (settings != null)
            {
                if (ModelState.IsValid)
                {
                    FillBase(settings);
                    settings.UserID = CurrentUser.ID;
                    dto_GridSettings _old = _service_Settings.GetValue(settings.Key, CurrentUser.ID);
                    if (_old != null)
                    {
                        _old.Value = settings.Value;
                        _service_Settings.update(_old);
                    }
                    else
                    {
                        _service_Settings.update(settings);
                    }
                }
                else
                {
                    _res.FillError("model state is invalid");
                    _log.Error("model state is invalid");
                }
            }
            else
            {
                _res.FillError("setting is null");
                _log.Error("setting is null");
            }
            return(Ok(_res));
        }
Пример #4
0
        public IActionResult Update([FromBody] List <dto_Settings> settings)
        {
            GenericResponse _res = new GenericResponse();

            _res.FillSuccess();
            if (settings != null && settings.Count > 0)
            {
                if (ModelState.IsValid)
                {
                    foreach (var item in settings)
                    {
                        dto_Settings _old = _service_Settings.Get(item.ID);
                        _old.Conf_Value = item.Conf_Value;
                        _service_Settings.update(_old);
                    }
                }
                else
                {
                    _res.FillError("model state is invalid");
                    _log.Error("model state is invalid");
                }
            }
            else
            {
                _res.FillError("setting is null");
                _log.Error("setting is null");
            }
            return(Ok(_res));
        }
Пример #5
0
        // POST api/<controller>
        public IActionResult CreateMultiple([FromBody] CreateMultipleViewModel Users)
        {
            GenericResponse response = new GenericResponse();
            List <string>   Errors   = new List <string>();

            if (ModelState.IsValid)
            {
                response.FillSuccess();
                if (Users != null && Users.users != null && Users.users.Count > 0)
                {
                    foreach (var Model in Users.users)
                    {
                        try
                        {
                            fillservices();
                            FillBase(Model.Model);
                            if (_service_account.validate(Model.Model))
                            {
                                Model.Model.Groups      = Model.Groups_Selected;
                                Model.Model.Privilliges = Model.Privilliges_Selected;
                                _service_User.CreateOREdit(Model.Model);
                                //response.data = Model;
                            }
                            else
                            {
                                Errors.Add(Model.Model.Email + "Already Exist");
                                response.FillError(Model.Model.Email + "Already Exist");
                            }
                        }
                        catch (Exception ex)
                        {
                            Errors.Add(ex.Message);
                            response.FillError(ex);
                        }
                    }
                }
                else
                {
                    response.FillError("Empty users");
                }
            }
            else
            {
                response.FillError("Model state is not valid");
            }
            if (Errors.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var item in Errors)
                {
                    sb.AppendLine(item);
                }
                response.FillError(sb.ToString());
            }
            return(Ok(response));
        }
Пример #6
0
        public IActionResult ChangePassword([FromBody] ChangePasswordVM model)
        {
            GenericResponse res = new GenericResponse();

            res.FillSuccess();
            if (model != null && model.confirmPassword == model.password && !string.IsNullOrEmpty(model.password))
            {
                _service_account.ChangePassword(CurrentUser.ID, model.password);
            }
            else
            {
                res.FillError();
            }
            return(Ok(res));
        }
Пример #7
0
        public IActionResult ChangePassword([FromBody] LoginViewModel Model)
        {
            GenericResponse response = new GenericResponse();

            response.FillSuccess();
            if (Model != null && !string.IsNullOrEmpty(Model.Password))
            {
                _service_User.ChangePassword(CurrentUser.ID, Model.Password);
            }
            else
            {
                response.FillError("password Is empty");
            }
            return(Ok(response));
        }
Пример #8
0
        // POST api/<controller>
        public IActionResult Create([FromBody] dto_User Model)
        {
            GenericResponse response = new GenericResponse();

            if (ModelState.IsValid)
            {
                response.FillSuccess();
                FillBase(Model);
                if (_service_account.validate(Model))
                {
                    _service_User.CreateOREdit(Model);
                    response.data = Model;
                }
                else
                {
                    response.FillError("Already Exist");
                }
            }
            else
            {
                response.FillError();
            }
            return(Ok(response));
        }
        public IActionResult ChangeArabic()
        {
            GenericResponse _res = new GenericResponse();

            _res.FillSuccess();
            try
            {
                string _token = base.GetTokenForArabic();
                _res.data = _token;
            }
            catch (Exception ex)
            {
                _res.FillError("Failed");
            }
            return(Ok(_res));
        }
Пример #10
0
        // DELETE api/<controller>/5
        public IActionResult Validate([FromBody] LoginViewModel Model)
        {
            GenericResponse response = new GenericResponse();

            response.FillSuccess();
            if (ModelState.IsValid)
            {
                var res = _helper_activeDirectory.Validate(Model.Username, Model.Password);
                response.data = res;
            }
            else
            {
                response.FillError("UserName Is empty");
            }
            return(Ok(response));
        }
Пример #11
0
        // POST api/<controller>
        public IActionResult Create([FromBody] dto_Privillige Model)
        {
            GenericResponse response = new GenericResponse();

            if (ModelState.IsValid)
            {
                response.FillSuccess();
                FillBase(Model);
                _service_Privillige.CreateOREdit(Model);
                response.data = Model;
            }
            else
            {
                response.FillError();
            }
            return(Ok(response));
        }
Пример #12
0
        public IActionResult register([FromBody] RegisterModel input)
        {
            GenericResponse response = new GenericResponse();

            response.FillSuccess();
            FillBase(input.User);

            if (_service_account.validate(input.User))
            {
                input.User.isActivated         = true;
                input.User.ActivationStartDate = DateTime.Now;
                _service_account.register(input.User);
            }
            else
            {
                response.FillError("Already Exist");
            }
            return(Ok(response));
        }
Пример #13
0
        // POST api/<controller>
        public IActionResult Create([FromBody] dto_Group Model)
        {
            GenericResponse response = new GenericResponse();

            if (ModelState.IsValid)
            {
                //Model.Model.Privilliges = Model.Privilliges_Selected;
                response.FillSuccess();
                //FillBase(Model.Model);
                FillBase(Model);

                //_service_Group.CreateOREdit(Model.Model);
                _service_Group.CreateOREdit(Model);
                response.data = Model;
            }
            else
            {
                response.FillError();
            }
            return(Ok(response));
        }
Пример #14
0
        public IActionResult Login([FromBody] dto_User input)
        {
            GenericResponse _res = new GenericResponse();

            _res.FillSuccess();
            if (input != null)
            {
                var user = _service_account.GetUser(input.Email);

                if (user != null)
                {
                    if (user.isAD)
                    {
                        var valid = _helper_activeDirectory.Validate(input.Email, input.Password);
                        if (valid)
                        {
                            user = _service_account.loginAD(input.Email);
                        }
                        else
                        {
                            user = null;
                            _res.FillError("User NotFound");
                        }
                    }
                    else if (input.IsThirdParty)
                    {
                        user = _service_account.login(input.Email);
                    }
                    else
                    {
                        user = _service_account.login(input.Email, input.Password);
                    }
                }
                else
                {
                    if (input.IsThirdParty)
                    {
                        FillBase(input);
                        input.ActivationStartDate = DateTime.Now;
                        input.isActivated         = true;

                        _service_account.register(input);
                        user = _service_account.login(input.Email);
                    }
                    else
                    {
                        _res.FillError("User NotFound");
                    }
                }
                if (user != null)
                {
                    if (user.isActivated && user.ActivationStartDate.HasValue && user.ActivationStartDate.Value <= DateTime.Now &&
                        (user.ActivationEndDate.HasValue == false || user.ActivationEndDate <= DateTime.Now)
                        )
                    {
                        UserTokenModel model = new UserTokenModel();
                        model.IsEnglish = true;
                        emptyUser(user);
                        model.User = user;
                        string token = GenerateToken_HS256(model);
                        //string token = GenerateToken_RS256(user);
                        //string Decoded = decodeToken_RS256(token);
                        _res.data = token;
                    }
                    else
                    {
                        _res.FillError("User is not activated");
                    }
                    return(Ok(_res));
                }
                else
                {
                    _res.FillError("User NotFound");
                    return(Ok(_res));
                }
            }
            else
            {
                _res.FillError("User NotFound");
                return(Ok(_res));
            }
        }