Exemplo n.º 1
0
        public async Task <ActionResult> ConfirmEmail(string userId, string offerToken, string code)
        {
            if (userId == null || offerToken == null)
            {
                return(View("Error"));
            }
            OfferService offerService      = new OfferService();
            var          model             = new DealRegisterViewModel();
            var          offer             = offerService.GetOfferByToken(offerToken);
            var          existingOfferCode = CodeForUser(offer.Id, userId);

            if (existingOfferCode == null)//if user does not have code yet, claim next
            {
                var offerCode = offerService.ClaimNextCode(offer.Id, userId);
                model.OfferCode   = offerCode;
                model.Title       = offer.Title;
                model.Description = offer.Description;
                model.Url         = offer.Url;
            }
            else//otherwise use the code that user already has
            {
                model.OfferCode   = existingOfferCode;
                model.Title       = offer.Title;
                model.Description = offer.Description;
                model.Url         = offer.Url;
            }
            var result = await UserManager.ConfirmEmailAsync(userId, code);

            if (result.Succeeded)
            {
                return(View("ConfirmEmail", model));
            }
            else
            {
                return(View("Error"));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ConfirmEmailJson(string userId, string offerToken, string code)
        {
            var confirmEmailResult = new DealConfirmEmailResult();

            if (userId == null || offerToken == null)
            {
                var errors = Json(confirmEmailResult);
                if (userId == null)
                {
                    confirmEmailResult.IsSuccessful = false;
                    confirmEmailResult.ErrorMessages.Add("userId invalid");
                    errors = Json(confirmEmailResult);
                }
                if (offerToken == null)
                {
                    confirmEmailResult.IsSuccessful = false;
                    confirmEmailResult.ErrorMessages.Add("offerToken invalid");
                    errors = Json(confirmEmailResult);
                }
                errors.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                return(errors);
            }
            OfferService offerService = new OfferService();
            var          model        = new DealRegisterViewModel();
            var          offer        = offerService.GetOfferByToken(offerToken);
            //TODO: If offer is null we need to return unsuccessful Message: "Offer not found"
            var existingOfferCode = CodeForUser(offer.Id, userId);

            if (existingOfferCode == null)//if user does not have code yet, claim next
            {
                var offerCode = offerService.ClaimNextCode(offer.Id, userId);
                model.OfferCode   = offerCode;
                model.Title       = offer.Title;
                model.Description = offer.Description;
                model.Url         = offer.Url;
            }
            else//otherwise use the code that user already has
            {
                model.OfferCode   = existingOfferCode;
                model.Title       = offer.Title;
                model.Description = offer.Description;
                model.Url         = offer.Url;
            }
            //TODO: Handle if userId is bad.
            try
            {
                var result = await UserManager.ConfirmEmailAsync(userId, code);

                if (result.Succeeded)
                {
                    confirmEmailResult.IsSuccessful = true;
                    confirmEmailResult.Code         = model.OfferCode;
                    confirmEmailResult.Description  = model.Description;
                    confirmEmailResult.Url          = model.Url;
                    var success = Json(confirmEmailResult);
                    success.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                    return(success);
                }
                else
                {
                    confirmEmailResult.IsSuccessful = false;
                    confirmEmailResult.Code         = null;
                    //TODO: change error message assignment to foreach
                    confirmEmailResult.ErrorMessages[0] = "Unhandled error occurred.";
                    var errors = Json(confirmEmailResult);
                    errors.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                    return(errors);
                }
            }
            catch (System.InvalidOperationException ex)
            {
                confirmEmailResult.IsSuccessful = false;
                confirmEmailResult.ErrorMessages.Add(ex.Message);
                var errors = Json(confirmEmailResult);
                errors.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                return(errors);
            }
            catch (Exception ex)
            {
                confirmEmailResult.IsSuccessful = false;
                confirmEmailResult.ErrorMessages.Add("Unknown Error");
                var errors = Json(confirmEmailResult);
                errors.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                return(errors);
            }
        }
Exemplo n.º 3
0
        public void ClaimOfferCodeCRUD()
        {
            var Offer           = new Offer();
            var testTitle       = "Necklaces";
            var testDescription = "80% off these shiny necklaces!";
            var testUrl         = "fakeurl.bamazon.necklaces/";
            var testCategory    = "Jewelry";



            var testCompanyId = RandomInteger();

            Offer.Title       = testTitle;
            Offer.Description = testDescription;
            Offer.Url         = testUrl;
            Offer.Category    = testCategory;
            Offer.CompanyId   = testCompanyId;

            //create (offercode)
            var offerCode1 = new OfferCode();

            offerCode1.Code = "ABCDEF" + RandomDigits();
            var offerCode2 = new OfferCode();

            offerCode2.Code = "GHIJKL" + RandomDigits();
            var offerCode3 = new OfferCode();

            offerCode3.Code = "MNOPQR" + RandomDigits();

            offerCode1.OfferId = Offer.Id;
            offerCode2.OfferId = Offer.Id;
            offerCode3.OfferId = Offer.Id;

            OfferService offerService = new OfferService();

            offerService.SaveOffer(Offer);
            Assert.IsTrue(Offer.Id != 0);

            offerCode1.OfferId = Offer.Id;
            offerCode2.OfferId = Offer.Id;
            offerCode3.OfferId = Offer.Id;

            offerService.SaveOfferCode(offerCode1);
            offerService.SaveOfferCode(offerCode2);
            offerService.SaveOfferCode(offerCode3);
            Assert.IsTrue(offerCode1.Id != 0);
            Assert.IsTrue(offerCode2.Id != 0);
            Assert.IsTrue(offerCode3.Id != 0);

            var userId1 = "Jackie Bolton";

            var code1 = offerService.ClaimNextCode(Offer.Id, userId1);

            Assert.IsTrue(!String.IsNullOrEmpty(code1));
            //Verify that the first code is claimed by Jackie
            offerCode1 = offerService.GetOfferCode(offerCode1.Id);
            Assert.IsTrue(offerCode1.ClaimingUser.Equals(userId1));

            var userId2 = "Sandra Lollygagger";

            var code2 = offerService.ClaimNextCode(Offer.Id, userId2);

            Assert.IsTrue(!String.IsNullOrEmpty(code2));
            //Verify that the second code is claimed by Sandra
            offerCode2 = offerService.GetOfferCode(offerCode2.Id);
            Assert.IsTrue(offerCode2.ClaimingUser.Equals(userId2));
            Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode2.ClaimingUser));

            var userId3 = "Kevin Spaceman";

            var code3 = offerService.ClaimNextCode(Offer.Id, userId3);

            Assert.IsTrue(!String.IsNullOrEmpty(code3));
            //Verify that the third code is claimed by Kevin
            offerCode3 = offerService.GetOfferCode(offerCode3.Id);
            Assert.IsTrue(offerCode3.ClaimingUser.Equals(userId3));
            Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode3.ClaimingUser));

            var userId4 = "Richmond Nocode";

            var code4 = offerService.ClaimNextCode(Offer.Id, userId4);

            //This time verifying that code4 IS empty because we have no more codes in the offer.
            Assert.IsTrue(String.IsNullOrEmpty(code4));

            offerService.DeleteOfferCode(offerCode1.Id);
            offerService.DeleteOfferCode(offerCode2.Id);
            offerService.DeleteOfferCode(offerCode3.Id);

            offerService.DeleteOffer(Offer.Id);
        }