Exemplo n.º 1
0
 public ServiceResult<LogLogin> Edit(LogLogin obj)
 {
     try
     {
         IMediator service = _container.GetInstance<IMediator>();
         IUserContext currentUser = _container.GetInstance<IUserContext>();
         var query = new LogLoginEditQuery();
         query.LogLogin = obj;
         return new ServiceResult<LogLogin>(service.Proccess(query), message: ClientErrorMessage.Success(), state: ServiceResultStates.SUCCESS);
     }
     catch (ExceptionLog ex)
     {
         LoggerService.Logger.Log(_container, ex);
         return new ServiceResult<LogLogin>(result: null, message: ClientErrorMessage.Error(), state: ServiceResultStates.ERROR);
     }
 }
Exemplo n.º 2
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            User user = null;
            if (!string.IsNullOrEmpty(context.UserName) && !string.IsNullOrEmpty(context.Password))
            {
                AuthenticateService service = new AuthenticateService(_container);
                LogLoginService loginLogService = new LogLoginService(_container);
                LogLogin logLoginObj = new LogLogin();
                user = service.Authenticate(context.UserName, context.Password);
                if (user != null)
                {
                    var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                    identity.AddClaim(new Claim("name", user.Name));
                    identity.AddClaim(new Claim("email", user.Email));
                    identity.AddClaim(new Claim("userid", user.Id.ToString()));
                    identity.AddClaim(new Claim("usertype", user.UserType.ToString()));
                    identity.AddClaim(new Claim("companyid", user.Company.Id.ToString()));
                    identity.AddClaim(new Claim("companyname", user.Company.Name));
                    identity.AddClaim(new Claim("ipaddress", context.Request.RemoteIpAddress));

                    context.Validated(identity);

                    logLoginObj.LoginLogType = LoginLogType.SUCCESS.ToString();
                    logLoginObj.UserId = user.Id;
                }
                else
                {
                    logLoginObj.LoginLogType = LoginLogType.FAILED.ToString();
                    logLoginObj.Comment = "Başarısız Giriş";
                    logLoginObj.ExceptionString = string.Format("UserName:{0} - Password:{1} ", context.UserName, context.Password);
                }
                logLoginObj.IsDeleted = false;
                logLoginObj.LogDate = DateTime.Now;
                loginLogService.Add(logLoginObj);
            }

            //if (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Password))
            //{
            //    var user = service.Authenticate(Email, Password);
            //    if (user != null)
            //    {
            //        var authentication = Request.GetOwinContext().Authentication;
            //        var identity = new ClaimsIdentity("Bearer");
            //        identity.AddClaim(new Claim("name", user.Name));
            //        identity.AddClaim(new Claim("email", user.Email));
            //        identity.AddClaim(new Claim("userid", user.Id.ToString()));
            //        identity.AddClaim(new Claim("isadmin", user.UserType.Value == 1 ? "true" : "false"));

            //        AuthenticationTicket ticket = new AuthenticationTicket(identity, new AuthenticationProperties());
            //        var currentUtc = new Microsoft.Owin.Infrastructure.SystemClock().UtcNow;
            //        ticket.Properties.IssuedUtc = currentUtc;
            //        ticket.Properties.ExpiresUtc = currentUtc.Add(TimeSpan.FromMinutes(30));
            //        var token = Startup.OAuthServerOptions.AccessTokenFormat.Protect(ticket);

            //        authentication.SignIn(identity);

            //        return token;
            //    }
            //}

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
            }


            return Task.FromResult<object>(null);
        }
 	public ServiceResult<LogLogin> Edit(LogLogin obj)
 	{
 		LogLoginService service = new LogLoginService(_container);
 		return service.Edit(obj);
 	}