예제 #1
0
        public async Task <ActionResult> PutMicrosoftAccount(string id)
        {
            string addressBookBlobUri = this.Request.Form["addressBookBlobUri"];

            new Uri(addressBookBlobUri, UriKind.Absolute);             // throws if invalid arg

            if (id != this.HttpContext.User.Identity.Name)
            {
                return(new HttpUnauthorizedResult());
            }

            var entity = await this.ClientTable.GetAsync(AddressBookEntity.MicrosoftProvider, this.HttpContext.User.Identity.Name);

            if (entity == null)
            {
                entity          = new AddressBookEntity();
                entity.Provider = AddressBookEntity.MicrosoftProvider;
                entity.UserId   = this.HttpContext.User.Identity.Name;
                this.ClientTable.AddObject(entity);
            }
            else
            {
                this.ClientTable.UpdateObject(entity);
            }

            entity.AddressBookUrl = addressBookBlobUri;

            await this.ClientTable.SaveChangesAsync();

            return(new EmptyResult());
        }
예제 #2
0
        private async Task SaveAccountInfoAsync(MicrosoftAccountInfo microsoftAccountInfo)
        {
            Requires.NotNull(microsoftAccountInfo, "microsoftAccountInfo");
            Requires.That(microsoftAccountInfo.Emails != null && microsoftAccountInfo.Emails.Count > 0, "microsoftAccountInfo", "No emails were provided by Live Connect.");

            var entity = await this.ClientTable.GetAsync(AddressBookEntity.MicrosoftProvider, microsoftAccountInfo.Id);

            if (entity == null)
            {
                entity          = new AddressBookEntity();
                entity.Provider = AddressBookEntity.MicrosoftProvider;
                entity.UserId   = microsoftAccountInfo.Id;
                this.ClientTable.AddObject(entity);
            }
            else
            {
                this.ClientTable.UpdateObject(entity);
            }

            entity.FirstName = microsoftAccountInfo.FirstName;
            entity.LastName  = microsoftAccountInfo.LastName;

            var previouslyRecordedEmails = await this.ClientTable.GetEmailAddressesAsync(entity);

            var previouslyRecordedEmailAddresses = new HashSet <string>(previouslyRecordedEmails.Select(e => e.Email));

            previouslyRecordedEmailAddresses.ExceptWith(microsoftAccountInfo.Emails.Values);

            var freshEmailAddresses = new HashSet <string>(microsoftAccountInfo.Emails.Values.Where(v => v != null));

            freshEmailAddresses.ExceptWith(previouslyRecordedEmails.Select(e => e.Email));

            foreach (var previouslyRecordedEmailAddress in previouslyRecordedEmailAddresses)
            {
                this.ClientTable.DeleteObject(
                    previouslyRecordedEmails.FirstOrDefault(e => e.Email == previouslyRecordedEmailAddress));
            }

            foreach (var freshEmailAddress in freshEmailAddresses)
            {
                var newEmailEntity = new AddressBookEmailEntity
                {
                    Email = freshEmailAddress,
                    MicrosoftEmailHash      = MicrosoftTools.GetEmailHash(freshEmailAddress),
                    AddressBookEntityRowKey = entity.RowKey,
                };
                this.ClientTable.AddObject(newEmailEntity);
            }

            await this.ClientTable.SaveChangesAsync();
        }
예제 #3
0
        public async Task <ActionResult> GetAddressBookEntryByEmailHash(string email, string emailHash)
        {
            AddressBookEntity entry = null;

            if (!string.IsNullOrEmpty(email))
            {
                entry = await this.ClientTable.GetAddressBookEntityByEmailAsync(email);
            }
            else if (!string.IsNullOrEmpty(emailHash))
            {
                entry = await this.ClientTable.GetAddressBookEntityByEmailHashAsync(emailHash);
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (entry == null)
            {
                return(this.HttpNotFound());
            }

            return(this.Redirect(entry.AddressBookUrl));
        }