Exemple #1
0
        public async Task <BaseHttpActionResult> GetFormattedStyles([FromUri] GetFormattedRuleVM model)
        {
            if (string.IsNullOrEmpty(model.entity_id))
            {
                model.entity_id = null;
            }

            if ((model.Scope != RuleEntityScope.Global && model.Scope != RuleEntityScope.User) &&
                string.IsNullOrEmpty(model.entity_id))//is not a global neither a user scope
            {
                return(ErrorHttpActionResult.GenerateBadRequest("You have to provide entityId if the scope is not global neither user"));
            }
            if (model.Scope == RuleEntityScope.User)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    return(new ErrorHttpActionResult(HttpStatusCode.Unauthorized, new ErrorResponse("You have to login to access user styles")));
                }
            }

            var styles = await _repo.GetStyles(model.Scope, UserId, model.entity_id);

            StringBuilder sb = new StringBuilder();

            foreach (var item in styles)
            {
                sb.Append(item.Format(model.base_url) + "\n");
            }
            return(new SuccessHttpActionResult(sb.ToString()));
        }
Exemple #2
0
        public async Task <BaseHttpActionResult> VerifyForgotPasswordEmail([Required] VerifyForgotPasswordEmailViewModel forgotPasswordViewModel)
        {
            var user = await _repo.FindUserWithEmail(forgotPasswordViewModel.Email);

            if (user == null)
            {
                return(ErrorHttpActionResult.GenerateBadRequest("no user registered with this email"));
            }
            return(await SendEmailVerificationCode(forgotPasswordViewModel));
        }
Exemple #3
0
        public async Task <BaseHttpActionResult> Register([Required] UserViewModel userModel)
        {
            var generatedCode = Common.Core.Utilities.OneAppUtility.GetCodeForValue(userModel.HashKey, userModel.Email);

            if (generatedCode.Code != userModel.VerificationCode)
            {
                return(ErrorHttpActionResult.GenerateBadRequest("Invalid or expired code"));
            }
            IdentityResult result = await _repo.RegisterUser(userModel.Username, userModel.Password,
                                                             userModel.Email, userModel.PhoneNumber, true);

            return(GetResult(result));
        }
Exemple #4
0
        public async Task <BaseHttpActionResult> ChangePassword([Required] ChangePasswordViewModel changePasswordViewModel)
        {
            //load user using username and provided password
            var user = await _repo.FindUser(this.User.Identity.GetUserName(), changePasswordViewModel.CurrentPassword);

            if (user == null)
            {
                return(ErrorHttpActionResult.GenerateBadRequest("The current password is invalid"));
            }

            IdentityResult result = await _repo.ChangePassword(user.Id, changePasswordViewModel.CurrentPassword, changePasswordViewModel.NewPassword);

            return(GetResult(result));
        }
Exemple #5
0
        public async Task <BaseHttpActionResult> ResetPassword([Required] ResetPasswordViewModel resetPasswordViewModel)
        {
            var user = await _repo.FindUserWithEmail(resetPasswordViewModel.Email);

            if (user == null)
            {
                return(ErrorHttpActionResult.GenerateBadRequest("no user registered with this email"));
            }
            var generatedCode = Common.Core.Utilities.OneAppUtility.GetCodeForValue(resetPasswordViewModel.HashKey, resetPasswordViewModel.Email);

            if (generatedCode.Code != resetPasswordViewModel.VerificationCode)
            {
                return(ErrorHttpActionResult.GenerateBadRequest("Invalid or expired code"));
            }

            string token = await _repo.GeneratePasswordResetToken(user.Id.ToString());

            IdentityResult result = await _repo.ResetPassword(user.Id, token, resetPasswordViewModel.Password);

            return(GetResult(result));
        }
Exemple #6
0
        public async Task <BaseHttpActionResult> UpdateRuleStyle()
        {
            var ruleJson = HttpContext.Current.Request.Form["rule"];
            var baseUrl  = HttpContext.Current.Request.Form["base_url"];
            var entityId = HttpContext.Current.Request.Form["entity_id"];

            if (string.IsNullOrEmpty(entityId))
            {
                entityId = null;
            }
            if (string.IsNullOrEmpty(ruleJson))
            {
                return(ErrorHttpActionResult.GenerateBadRequest("rule form data is required"));
            }
            RuleDTO rule = JsonConvert.DeserializeObject <RuleDTO>(ruleJson);

            // Get the uploaded files from the Files collection , add data to the fileinfo
            IList <FileDataDTO> fileDtos = new List <FileDataDTO>();

            foreach (var cssProperty in HttpContext.Current.Request.Files.AllKeys)
            {
                var httpPostedFile = HttpContext.Current.Request.Files[cssProperty];

                int    length      = httpPostedFile.ContentLength;
                string contentType = httpPostedFile.ContentType;
                string name        = Path.GetFileName(httpPostedFile.FileName);

                var fileData = new FileDataDTO(cssProperty);
                fileData.Data        = new byte[length];
                fileData.Name        = name;
                fileData.Length      = length;
                fileData.ContentType = contentType;
                httpPostedFile.InputStream.Read(fileData.Data, 0, length);
                fileDtos.Add(fileData);
            }

            var updateRule = await _repo.UpdateRuleStyle(rule, fileDtos, UserId, entityId);

            return(new SuccessHttpActionResult(updateRule.Format(baseUrl)));
        }