Exemplo n.º 1
0
        public static IEnumerable <Document> GetAllDocuments(this ConnectContext context, ConnectUser connectUser)
        {
            if (connectUser == null)
            {
                throw new ArgumentException("ConnectUser is invalid");
            }

            IEnumerable <Document> result = new List <Document>();

            result = result.Concat(GetDocuments <TachographDocument>(context, connectUser));
            result = result.Concat(GetDocuments <UndownloadabilityDocument>(context, connectUser));
            result = result.Concat(GetDocuments <LetterForDecommissioningDocument>(context, connectUser));

            return(result.OrderByDescending(c => c.InspectionDate.GetValueOrDefault()));
        }
Exemplo n.º 2
0
        private static bool AuthenticateUser(OAuthGrantResourceOwnerCredentialsContext context, out ConnectUser user)
        {
            user = null;

            if (string.IsNullOrEmpty(context.UserName) || string.IsNullOrEmpty(context.Password))
            {
                context.SetError("invalid_grant", "The user name or password is incorrect");
                return(false);
            }
            user = context.OwinContext.Get <ConnectContext>().Users.ToList().FirstOrDefault(c => string.Equals(c.CompanyKey.Replace(" ", "").Trim(), context.UserName.Replace(" ", "").Trim(), StringComparison.CurrentCultureIgnoreCase));

            if (!context.OwinContext.Get <ApplicationUserManager>().CheckPassword(user, context.Password))
            {
                context.SetError("invalid_grant", "The user name or password is incorrect");
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
 private void SendConfirmationEmail(ConnectUser user)
 {
     SendEmail(user.Email, "Thank you for registering", "Thank you for your interest in <a href=\"https://www.webcalconnect.com/\">WebcalConnect.com</a>.  Your account has been created and you can log in straight away");
 }
Exemplo n.º 4
0
        private static ClaimsIdentity SetClaimsIdentity(OAuthGrantResourceOwnerCredentialsContext context, ConnectUser user)
        {
            var identity = new ClaimsIdentity("JWT");

            identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()));
            identity.AddClaim(new Claim("sub", context.UserName));

            var userRoles = context.OwinContext.Get <ApplicationUserManager>().GetRoles(user.Id);

            if (userRoles.Any(r => r == ConnectRoles.Admin))
            {
                userRoles = ConnectRoles.All;
            }

            foreach (var role in userRoles)
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, role));
            }

            SetPrincipal(new ClaimsPrincipal(identity));
            return(identity);
        }