Ejemplo n.º 1
0
        public ActionResult Register(string offerToken)
        {
            var   model        = new DealRegisterViewModel();
            var   offerService = new OfferService();
            Offer offer        = offerService.GetOfferByToken(offerToken);

            model.IsCodeAvailable = isCodeAvailable(offer.Id);
            model.Title           = offer.Title;
            model.Description     = offer.Description;
            model.OfferToken      = offerToken;
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(DealRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                //password = 8^)U/G/D49HKT{2R
                var offerService = new OfferService();
                var user         = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, "kf6Ua?a<2DhfZ<,t");

                if (result.Succeeded)
                {
                    //Line below commented out to prevent log in until the user is confirmed.
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link

                    //Create company with user ID


                    //Add user role of buyer
                    await UserManager.AddToRoleAsync(user.Id, "Buyer");


                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account", model.OfferToken);

                    // Uncomment to debug locally
                    // TempData["ViewBagLink"] = callbackUrl;


                    ViewBag.Message = "Please check your email to receive your code.";

#if DEBUG
                    ViewBag.Message += callbackUrl;
#endif
                    return(View("Info"));
                    //return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
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"));
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> RegisterJson(DealRegisterViewModel model)
        {
            var registerResult = new DealRegisterResult();

            if (ModelState.IsValid)
            {
                //password = kf6Ua?a<2DhfZ<,t
                var offerService = new OfferService();
                var user         = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user, "kf6Ua?a<2DhfZ<,t");

                if (result.Succeeded)
                {
                    //Line below commented out to prevent log in until the user is confirmed.
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link

                    //Create company with user ID


                    //Add user role of buyer
                    await UserManager.AddToRoleAsync(user.Id, "Buyer");


                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account", model.OfferToken);

                    registerResult.IsSuccessful   = true;
                    registerResult.SuccessMessage = "Please check your email to receive your code.";

#if DEBUG
                    registerResult.SuccessMessage += callbackUrl;
#endif
                    // Uncomment to debug locally
                    // TempData["ViewBagLink"] = callbackUrl;

                    var jsonResult = Json(registerResult);
                    jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                    return(jsonResult);
                    //return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result, registerResult);
                    registerResult.IsSuccessful = false;
                    var jsonResult = Json(registerResult);
                    jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

                    return(jsonResult);
                }
            }
            foreach (var value in ModelState.Values)
            {
                foreach (var error in value.Errors)
                {
                    registerResult.ErrorMessages.Add(error.ErrorMessage);
                }
            }
            var errorResult = Json(registerResult);
            errorResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            return(errorResult);
        }