Ejemplo n.º 1
0
        public AuthResult Login(LoginRequest loginRequest)
        {
            AuthResult authResult = new AuthResult();

            try
            {
                authResult = AccountHandler.Login(loginRequest);
                if (authResult.AuthStatus == AuthStatus.OK)
                {
                    authResult = JWTHandler.CreateToken(authResult);
                }
            }

            catch (Exception ex)
            {
                Logger.LogException(ex);
                authResult.AuthStatus = AuthStatus.ERROR;
            }

            if (authResult.AuthStatus != AuthStatus.OK)
            {
                ServiceHelper.ThrowBadRequest <AuthResult>(Request, authResult);
            }


            return(authResult);
        }
Ejemplo n.º 2
0
        private AuthStatus LoginGeral(LoginViewModel model)
        {
            AuthResult result = new AuthResult();

            if (!ModelState.IsValid)
            {
                return(AuthStatus.ERROR);
            }

            result = AccountHandler.Login(new LoginRequest()
            {
                UserName    = model.Email,
                Password    = model.Password,
                TokenMobile = model.tokenMobile,
                Device      = model.tipoDispositivo
            });

            WorkerEntity worker = WorkerRepository.Instance.GetByUserId(result.UserId);

            if (result.AuthStatus == AuthStatus.OK)
            {
                var claims = new List <Claim>();
                claims.Add(new Claim(ClaimTypes.Sid, result.UserId.ToString()));
                claims.Add(new Claim(ClaimTypes.Name, result.UserId.ToString()));
                claims.Add(new Claim(ClaimTypes.Email, model.Email));
                claims.Add(new Claim(ClaimTypes.NameIdentifier, result.UserId.ToString()));
                claims.Add(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "http://vlast.com.br"));

                bool isSystemAdmin = false;
                foreach (var role in result.UserRoles)
                {
                    if (role == Roles.ADMINISTRATOR)
                    {
                        isSystemAdmin = true;
                    }

                    claims.Add(new Claim(ClaimTypes.Role, role.ToString()));
                }


                if (!isSystemAdmin)
                {
                    //WorkerEntity worker = WorkerRepository.Instance.GetByUserId(result.UserId);
                    WorkerTypeEntity profile = WorkerTypeRepository.Instance.GetById(worker.WorkerTypeId);
                    claims.Add(new Claim(ClaimTypes.Role, profile.ProfileName.ToString()));
                }

                var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

                var ctx = Request.GetOwinContext();
                var authenticationManager = ctx.Authentication;
                authenticationManager.SignIn(identity);

                return(AuthStatus.OK);
            }

            return(AuthStatus.ERROR);
        }
Ejemplo n.º 3
0
        public string LoginMobile(LoginViewModel model)
        {
            AuthResult      result = new AuthResult();
            PlayerEngineDTO player = null;
            string          json   = "";


            result = AccountHandler.Login(new LoginRequest()
            {
                UserName    = model.Email,
                Password    = model.Password,
                TokenMobile = model.tokenMobile,
                Device      = model.tipoDispositivo
            });

            if (result.AuthStatus == AuthStatus.OK)
            {
                try
                {
                    player          = PlayerEngineService.Instance.GetByEmail(model.Email);
                    player.LogoPath = GetImagePath(player.LogoId);
                }
                catch (Exception e)
                {
                }

                json = JsonConvert.SerializeObject(
                    player,
                    Formatting.Indented,
                    new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                }
                    );

                return(json);
            }

            json = JsonConvert.SerializeObject(
                new
            {
                error = result.AuthStatus.ToString()
            },
                Formatting.Indented,
                new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }
                );

            return(json);
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var accountHandler = new AccountHandler();

            var user = accountHandler.Login(new LoginContract
            {
                Username = context.UserName,
                Password = context.Password
            });

            if (user != null)
            {
                _user = user;
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim("sub", context.UserName));
                identity.AddClaim(new Claim("role", "user"));

                context.Validated(identity);
            }
            else
            {
                context.SetError("Failed to validate user.");
            }
        }
 public IHttpActionResult Login(LoginContract loginContract)
 {
     return(Ok(_loginHandler.Login(loginContract)));
 }
Ejemplo n.º 6
0
 public async Task <object> Execute()
 {
     return(await AccountHandler.Login(Email, Password, RememberMe));
 }
Ejemplo n.º 7
0
        public string Login(int loginCode, string password)
        {
            string token = handler.Login(loginCode, password);

            return(token);
        }