예제 #1
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var request = new LoginUserRequest()
            {
                Email    = model.Email,
                Password = Utils.Utils.PassGenerate(model.Password)
            };

            var userLogin = JsonConvert.DeserializeObject <UserResponse>
                                (ServiceApiUtil.ApiResponse("api/user/GetByLoginAndPass", "POST", request));

            if (userLogin != null)
            {
                var identify = new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.Name, userLogin.Email),
                    new Claim(ClaimTypes.Sid, userLogin.Id.ToString())
                },
                                                  "ApplicationCookie");
                var ctx         = Request.GetOwinContext();
                var authManager = ctx.Authentication;
                authManager.SignIn(identify);
                return(Redirect(GetRedirectUrl(model.ReturnUrl)));
            }

            ModelState.AddModelError("", "Usuário ou senha inválidos");
            return(View(model));
        }
예제 #2
0
        public ActionResult Create(UserModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create"));
            }

            var emailExists = JsonConvert.DeserializeObject <bool>
                                  (ServiceApiUtil.ApiResponse("api/user/EmailExists?request=" + user.Email, "GET"));

            if (emailExists)
            {
                ModelState.AddModelError("", "E-mail já cadastrado.");
                return(View(user));
            }
            var request = new InsertUserRequest()
            {
                Email    = user.Email,
                Password = Utils.Utils.PassGenerate(user.Password)
            };

            var response = JsonConvert.DeserializeObject <InsertUserResponse>
                               (ServiceApiUtil.ApiResponse("api/user/Insert", "POST", request));

            return(RedirectToAction("Login", new { returnUrl = "", message = "Usuário criado com sucesso." }));
        }
예제 #3
0
        private void TryAssembleFile(ResumableConfiguration configuration)
        {
            if (AllChunksAreHere(configuration))
            {
                // Create a single file
                var path      = ConsolidateFile(configuration);
                var extension = configuration.FileName.Split('.');
                var fileName  = Guid.NewGuid();
                // Rename consolidated with original name of upload
                RenameFile(path, Path.Combine(root, fileName.ToString() + (extension.Length > 1 ? "." + extension[extension.Length - 1] : "")));

                // Delete chunk files
                DeleteChunks(configuration);

                var request = new InsertFileRequest()
                {
                    CreatedDate = DateTime.Now,
                    IdUser      = int.Parse(User.GetUserId()),
                    Name        = configuration.FileName,
                    Size        = configuration.Size,
                    NomeInterno = fileName
                };

                JsonConvert.DeserializeObject <InsertFileResponse>
                    (ServiceApiUtil.ApiResponse("api/file/Insert", "POST", request));
            }
        }