Esempio n. 1
0
        public ManagedAccountEmailConfirmation Confirm(ManagedSecurityContext sec)
        {
            GetACL().Check(sec, DataOperation.All);

            if (this.Verified && ! this.mInstance.Failed)
                return null;

            // find and existing pending confirmation
            foreach (AccountEmailConfirmation c in Collection<AccountEmailConfirmation>.GetSafeCollection(mInstance.AccountEmailConfirmations))
            {
                if (c.AccountEmail.Id == Id)
                {
                    ManagedAccountEmailConfirmation existingac = new ManagedAccountEmailConfirmation(Session, c);
                    existingac.Send();
                    return existingac;
                }
            }

            AccountEmailConfirmation ac = new AccountEmailConfirmation();
            ac.AccountEmail = mInstance;
            ac.Code = Guid.NewGuid().ToString();
            ac.Modified = ac.Created = DateTime.UtcNow;
            Session.Save(ac);

            if (mInstance.AccountEmailConfirmations == null)
            {
                mInstance.AccountEmailConfirmations = new List<AccountEmailConfirmation>();
            }

            mInstance.AccountEmailConfirmations.Add(ac);

            ManagedAccountEmailConfirmation mac = new ManagedAccountEmailConfirmation(Session, ac);
            mac.Send();
            return mac;
        }
        public static string Verify(ISession session, int id, string code)
        {
            AccountEmailConfirmation confirmation = session.CreateCriteria(typeof(AccountEmailConfirmation))
                                                    .Add(Expression.Eq("Id", id))
                                                    .UniqueResult <AccountEmailConfirmation>();

            if (confirmation == null)
            {
                throw new Exception(string.Format("Error locating confirmation id \"{0}\".", id));
            }

            ManagedAccountEmailConfirmation c = new ManagedAccountEmailConfirmation(session, id);
            string emailaddress = c.Verify(code);

            SnCore.Data.Hibernate.Session.Flush();
            return(emailaddress);
        }