コード例 #1
0
        /// <summary>
        /// Crea un nuovo token
        /// </summary>
        /// <param name="UserId">Id Utente</param>
        /// <returns>Oggetto Token creato o vecchio Token</returns>
        public Token TokenCreate(Int64 UserId, Domain.Enums.TokenType Type)
        {
            if (UserId <= 0)
            {
                return(new Token());
            }

            TicketUser Usr = this.UserGet(UserId);

            if (Usr == null || Usr.Id <= 0)
            {
                return(new Token());
            }


            Token Tok = Manager.GetAll <Token>(tok => tok.User.Id == UserId).FirstOrDefault();

            //(from Token tok in Manager.GetIQ<Token>() where tok.User.Id == UserId select tok.Code).FirstOrDefault();

            if (Tok == null || Tok.Id <= 0)
            {
                Tok      = new Token(Usr, true);
                Tok.Type = Type;
                Manager.SaveOrUpdate <Token>(Tok);
            }

            return(Tok);
        }
コード例 #2
0
        public Domain.Enums.TokenValidationResult TokenValidate(String Code, Int64 UserId, Domain.Enums.TokenType Type)
        {
            if (String.IsNullOrEmpty(Code))
            {
                return(Domain.Enums.TokenValidationResult.InvalidFormat);
            }

            System.Guid TokGuid = Guid.Empty;
            try
            {
                TokGuid = new Guid(Code);
            }
            catch { }

            if (TokGuid == null || TokGuid == Guid.Empty)
            {
                return(Domain.Enums.TokenValidationResult.InvalidFormat);
            }

            return(TokenValidate(TokGuid, UserId, Type));
        }
コード例 #3
0
        /// <summary>
        /// Convalida un Token: se User valido lo cancella.
        /// </summary>
        /// <param name="Code"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public Domain.Enums.TokenValidationResult TokenValidate(Guid Code, Int64 UserId, Domain.Enums.TokenType Type)
        {
            if (Code == Guid.Empty)
            {
                return(Domain.Enums.TokenValidationResult.InvalidFormat);
            }

            if (UserId <= 0)
            {
                return(Domain.Enums.TokenValidationResult.UserNotFound);
            }

            TicketUser User = Manager.Get <TicketUser>(UserId);

            if (User == null || User.Id <= 0)
            {
                return(Domain.Enums.TokenValidationResult.UserNotFound);
            }

            IList <Token> Tokens = Manager.GetAll <Token>(tok => tok.Code == Code && tok.User.Id == UserId && tok.Type == Type);

            if (User.MailChecked == true)
            {
                Manager.DeletePhysicalList <Token>(Tokens);
                return(Domain.Enums.TokenValidationResult.Validated);
            }

            if (Tokens != null && Tokens.Any())
            {
                User.MailChecked = true;
                Manager.SaveOrUpdate <TicketUser>(User);
                Manager.DeletePhysicalList <Token>(Tokens);
                return(Domain.Enums.TokenValidationResult.Validated);
            }

            return(Domain.Enums.TokenValidationResult.TokenNotFound);
        }