Exemplo n.º 1
0
 public ActionResult ValidateSMSKey(PNCModel model)
 {
     ////model.SMSKey = string.Empty;
     //model = new PNCModel
     //{
     //    VerifcationKey = model.VerifcationKey,
     //    SMSKey = ""
     //};
     return(View());
 }
Exemplo n.º 2
0
        public ActionResult ValidateSMSKeySubmit(PNCModel model)
        {
            using (Data.ApplicationDbContext context = new Data.ApplicationDbContext())
            {
                var result = context.PNC.Where(x => x.VerifcationKey == model.VerifcationKey).FirstOrDefault(); //One Result
                if (result.SMSKey == model.SMSKey)
                {
                    result.IsValid = true;
                    context.Entry(result).State = EntityState.Modified;
                    context.SaveChanges();

                    ViewBag.Message = "You have been verified!";
                }
            }



            return(View("ValidateSMSKey", model));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Address = model.Address, Email = model.Email, PhoneNumber = model.PhoneNumber
                };

                //Result will contain the userId it generated.
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    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
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");


                    //---------------------------------------------------------
                    //Generating a key that will be sent to the new user
                    PNCModel pncModel = new PNCModel();
                    Random   r        = new Random();
                    pncModel.SMSKey = r.Next(0, 100000).ToString("000000");

                    //Call EntityFramework to save
                    using (Data.ApplicationDbContext context = new Data.ApplicationDbContext())
                    {
                        context.PNC.Add(pncModel); //Assign the values

                        try
                        {
                            context.SaveChanges(); //Save the changes

                            var accountSid = ConfigurationManager.AppSettings["SMSAccountIdentification"];
                            var authToken  = ConfigurationManager.AppSettings["SMSAccountPassword"];
                            TwilioClient.Init(accountSid, authToken);

                            var to   = new PhoneNumber(model.PhoneNumber);
                            var from = new PhoneNumber(ConfigurationManager.AppSettings["SMSAccountFrom"]);

                            var message = MessageResource.Create(
                                to: to,
                                from: from,
                                body: pncModel.SMSKey);

                            Content(message.Sid);

                            //Redirect user to a form in order to validate the keys
                            return(RedirectToAction("ValidateSMSKey", "Account", pncModel));
                        }
                        catch (Exception e)
                        {
                            //Do Somethings
                        }
                    }
                }
                AddErrors(result);
            }
            return(RedirectToAction("Index", "Home"));
        }