Exemplo n.º 1
0
        public CustomerModel Login(string userName, string password, bool createPersistentCookie = true)
        {
            var response = _customerRepository.Login(userName, password);
            var user     = response.Result;

            if (user == null)
            {
                return(null);
            }

            var now = DateTime.UtcNow.ToLocalTime();

            var sessionContext = DependencyResolver.Current.GetService <ISessionContext>();
            var sessionId      = sessionContext.SessionId;

            var session = new SessionUpdateModel()
            {
                CustomerId = user.UserId.ToString(),
                SessionId  = sessionId
            };

            _sessionRepository.UpdateUserSession(session);
            var ticket = new FormsAuthenticationTicket(
                1 /*version*/, user.UserId.ToString(),
                now,
                now.Add(_expirationTimeSpan),
                createPersistentCookie, user.UserId.ToString() + "~" + user.Username + "~" + sessionId.ToString(),
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = true
            };

            if (ticket.IsPersistent)
            {
                cookie.Expires = ticket.Expiration;
            }
            cookie.Secure = FormsAuthentication.RequireSSL;
            cookie.Path   = FormsAuthentication.FormsCookiePath;
            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            //added the following line assuming that this will set IsAuthenticated=true
            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
            //refer to teh following links, if the above does not works
            //http://stackoverflow.com/questions/1064271/asp-net-mvc-set-custom-iidentity-or-iprincipal
            //http://stackoverflow.com/questions/21679836/custom-identity-using-mvc5-and-owin
            //http://www.windowsdevcenter.com/pub/a/dotnet/2004/02/02/effectiveformsauth.html

            _httpContext.Response.Cookies.Add(cookie);
            _cachedUser    = user;
            user.SessionId = sessionId.ToString();
            return(user);
        }
Exemplo n.º 2
0
        public async Task <CinemaApp.Domain.Session> InsertAsync(SessionUpdateModel session)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <Session>(session));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <CinemaApp.Domain.Session>(result.Entity));
        }
Exemplo n.º 3
0
        public CustomerModel SocialLogin(string id)
        {
            var createPersistentCookie = true;
            var response = _customerRepository.GetUserdetailsById <CustomerModel>(id);
            var user     = response.Result;

            if (user == null)
            {
                return(null);
            }

            var now = DateTime.UtcNow.ToLocalTime();

            var sessionContext = DependencyResolver.Current.GetService <ISessionContext>();
            var sessionId      = sessionContext.SessionId;

            var session = new SessionUpdateModel()
            {
                CustomerId = user.UserId.ToString(),
                SessionId  = sessionId
            };

            _sessionRepository.UpdateUserSession(session);
            var ticket = new FormsAuthenticationTicket(
                1 /*version*/, user.UserId.ToString(),
                now,
                now.Add(_expirationTimeSpan),
                createPersistentCookie, user.UserId.ToString() + "~" + user.Username + "~" + sessionId.ToString(),
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
            {
                HttpOnly = true
            };

            if (ticket.IsPersistent)
            {
                cookie.Expires = ticket.Expiration;
            }
            cookie.Secure = FormsAuthentication.RequireSSL;
            cookie.Path   = FormsAuthentication.FormsCookiePath;
            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            //added the following line assuming that this will set IsAuthenticated=true
            FormsAuthentication.SetAuthCookie(user.Username, createPersistentCookie);

            _httpContext.Response.Cookies.Add(cookie);
            _cachedUser    = user;
            user.SessionId = sessionId.ToString();
            return(user);
        }
Exemplo n.º 4
0
 public void UpdateSession(string sessionId)
 {
     if (sessionId != null)
     {
         SessionUpdateModel info = new SessionUpdateModel()
         {
             SessionId = sessionId
         };
         _authenticationService.UpdateSession(info);
     }
 }
        public async Task <IActionResult> UpdateSessionByIdAsync([FromRoute] Guid id,
                                                                 [FromBody] SessionUpdateModel model)
        {
            var updated = await Service.UpdateAsync(id, model);

            if (updated == null)
            {
                return(NotFound());
            }
            return(Ok(updated));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> UpdateSession(Guid id, [FromBody] SessionUpdateModel sessionUpdateModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var sessionId = await _sessionService.Update(id, sessionUpdateModel);

            return(NoContent());
        }
Exemplo n.º 7
0
        public async Task <CinemaApp.Domain.Session> UpdateAsync(SessionUpdateModel session)
        {
            var existing = await this.Get(session);

            var result = this.Mapper.Map(session, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <CinemaApp.Domain.Session>(result));
        }
Exemplo n.º 8
0
        public async Task <Guid> Update(Guid id, SessionUpdateModel updatedSession)
        {
            var exist = await _readRepository.FindByIdAsync <Domain.Session>(id);

            if (exist != null)
            {
                exist.Update(exist.ConfirmationCode, updatedSession.ExtraDuration);
                await _writeRepository.UpdateAsync(id, exist);

                await _writeRepository.SaveAsync();
            }
            return(exist.Id);
        }
Exemplo n.º 9
0
        public async Task CreateAsync_SessionValidationSucceed_CreatesLoyaltyCard()
        {
            // Arrange
            var session  = new SessionUpdateModel();
            var expected = new Session();

            var sessionDAL = new Mock <ISessionDAL>();

            sessionDAL.Setup(x => x.InsertAsync(session)).ReturnsAsync(expected);

            var sessionService = new SessionService(sessionDAL.Object);

            // Act
            var result = await sessionService.CreateAsync(session);

            // Assert
            result.Should().Be(expected);
        }
        public async Task <SessionDetailsModel> UpdateAsync(Guid id, SessionUpdateModel model)
        {
            if (id.Equals(Guid.Empty))
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var found = await Repository.GetByIdAsync(id);

            if (found == null)
            {
                return(null);
            }


            Mapper.Map <SessionUpdateModel, Session>(model, found);
            // verify speaker id and audience id are valid
            var speaker = await SpeakersRepository.GetByIdAsync(found.SpeakerId);

            var audience = await AudiencesRepository.GetByIdAsync(found.AudienceId);

            if (speaker == null || audience == null)
            {
                throw new IndexOutOfRangeException();
            }

            found.Speaker  = speaker;
            found.Audience = audience;

            var updated = await Repository.UpdateAsync(found);

            await Audit.AuditCreatedAsync($"Session {updated.Title} has been updated");

            return(Mapper.Map <SessionDetailsModel>(updated));
        }
Exemplo n.º 11
0
 public async Task <Session> UpdateAsync(SessionUpdateModel session)
 {
     return(await this.SessionDAL.UpdateAsync(session));
 }
Exemplo n.º 12
0
 public void UpdateUserSession(SessionUpdateModel session)
 {
     CallApi <string>(ApiUrls.UpdateSession, JsonConvert.SerializeObject(session), Method.POST);
 }
Exemplo n.º 13
0
 public void UpdateSession(SessionUpdateModel info)
 {
     _sessionRepository.UpdateUserSession(info);
 }