Example #1
0
        public async Task <ActionResult> Authenticate(AuthenticateModel data)
        {
            if (string.IsNullOrEmpty(data.Username))
            {
                return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#username"));
            }

            if (string.IsNullOrEmpty(data.Password))
            {
                return(this.JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#password"));
            }

            var user =
                await
                _backOfficeUsersRepository.AuthenticateAsync(data.Username, data.Password);

            if (user == null)
            {
                return(this.JsonFailResult(Phrases.InvalidUsernameOrPassword, "#password"));
            }
            var sessionId = this.GetSession();


            await _browserSessionsRepository.SaveSessionAsync(sessionId, user.Id);

            SignIn(user);

            var divResult = Request.Browser.IsMobileDevice ? "#pamain" : "body";

            return(this.JsonRequestResult(divResult, Url.Action(nameof(BackOfficeController.Layout), "BackOffice")));
        }
Example #2
0
        public async Task <IActionResult> Authenticate(AuthenticateModel data)
        {
            if (string.IsNullOrEmpty(data.Username))
            {
                return(JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#username"));
            }

            if (string.IsNullOrEmpty(data.Password))
            {
                return(JsonFailResult(Phrases.FieldShouldNotBeEmpty, "#password"));
            }

            var user = await UsersRepository.AuthenticateAsync(data.Username, data.Password);

            if (user == null)
            {
                return(JsonFailResult(Phrases.InvalidUsernameOrPassword, "#password"));
            }

            var sessionId = GetSession();

            await _browserSessionsRepository.SaveSessionAsync(sessionId, user.Id);

            await SignIn(user);

            var divResult = Request.IsMobileBrowser() ? "#pamain" : "body";

            return(JsonRequestResult(divResult, Url.Action("Layout")));
        }