Exemplo n.º 1
0
        public async Task <ActionResult> TutorRegister(TutorRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                string EncodedResponse = Request.Form["g-Recaptcha-Response"];
                bool   IsCaptchaValid  = (Recaptcha.Validate(EncodedResponse) == "true" ? true : false);

                if (IsCaptchaValid)
                {
                    var check = Utility.CheckUserAge(model.Birthday);
                    if (check == false)
                    {
                        ViewData["Message"] = "You are too young!";
                        return(View(model));
                    }

                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var user2 = UserManager.FindByEmail(model.Email);

                        new TutorRepository().SaveTutor(
                            new Tutor()
                        {
                            Name         = model.Name,
                            Email        = user2.Email,
                            Birthday     = model.Birthday,
                            Address      = model.Address,
                            Postcode     = model.Postcode,
                            NiN          = model.NiN,
                            MobileNumber = model.MobileNumber,
                            UserId       = user2.Id
                        });

                        new RolesRepository().UserManger().AddToRoles(user2.Id, "Tutor");
                        string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

                        ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                          + "before you can log in.";
                        ViewBag.UserId = user.Id;
                        return(View("Info"));
                    }
                    ViewData["Message"] = "User already exist!";
                    AddErrors(result);
                }
                else
                {
                    TempData["recaptcha"] = "Please verify that you are not a robot!";
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Tutor()
        {
            TutorRegisterViewModel model = new TutorRegisterViewModel();

            model.TuitionSubjects = new List <TuitionSubjectsViewModel>()
            {
                new TuitionSubjectsViewModel {
                    Name = "K-5th", Description = "K-5th", Selected = false, TutorId = 0
                },
                new TuitionSubjectsViewModel {
                    Name = "6th-8th", Description = "6th-8th", Selected = false, TutorId = 0
                },
                new TuitionSubjectsViewModel {
                    Name = "FSA/EOC", Description = "FSA/EOC", Selected = false, TutorId = 0
                },
                new TuitionSubjectsViewModel {
                    Name = "World Languages (Spanish)", Description = "World Languages (Spanish)", Selected = false, TutorId = 0
                }
            };
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Tutor(TutorRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var _existUser = await UserManager.FindByEmailAsync(model.Email);

                if (_existUser != null)
                {
                    await UserManager.UpdateAsync(_existUser);

                    ViewBag.Message = "Email Already Exists.";
                    ModelState.AddModelError("", "Email Already Exists.");
                    return(View(model));
                }

                //profile upload
                if (model.File != null)
                {
                    //var supportedTypes = new[] { "jpg", "jpeg", "png", "gif" };
                    //var fileExt = System.IO.Path.GetExtension(model.File.FileName).Substring(1);

                    try
                    {
                        var supportedTypes = new[] { "jpg", "jpeg", "png", "gif", "tif" };
                        var fileExt        = System.IO.Path.GetExtension(model.File.FileName).Substring(1);
                        if (supportedTypes.Contains(fileExt.ToLower()))
                        {
                            var profileImage = Guid.NewGuid() + Path.GetExtension(model.File.FileName);
                            model.File.SaveAs(HttpContext.Server.MapPath("~/Content/images/tutor/") + profileImage);
                            model.ProfileImage = profileImage;
                        }
                    }
                    catch (Exception exi)
                    {
                    }
                }

                var user = new ApplicationUser
                {
                    UserName     = model.Email,
                    Email        = model.Email,
                    Title        = model.Title,
                    Gender       = model.Gender,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    PhoneNumber  = model.Mobile,
                    Address      = model.Address == null ? model.City + " " + model.Country + " " + model.Zip : model.Address,
                    City         = model.City,
                    TimeZone     = model.TimeZone,
                    Country      = model.Country,
                    Zip          = model.Zip,
                    Bio          = model.Bio, //summary
                    Hobbies      = model.Hobbies,
                    ProfileImage = model.ProfileImage,
                    //DOB = DateTime.Now.AddYears(-29),
                    CreatedDate = DateTime.Now,
                    //UpdatedDate = DateTime.Now
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Tutor");
                    var __tutor = await this._accountService.CreateTutorsAsync(new Tutors
                    {
                        UserId       = user.Id,
                        Experience   = model.Experience,
                        GradeLevel   = model.GradeLevel,
                        NameOfSchool = model.GradeLevel,
                        //Concerns
                        PreviousSubjects = model.GradeLevel
                    });

                    try
                    {
                        if (model.TuitionSubjects != null && __tutor.Id > 0)
                        {
                            await this._accountService.AddTutorSubjectAsync(model.TuitionSubjects, __tutor.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // 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",
                                                     "Hi " + model.FirstName + ",<br/><br/>"
                                                     + "Thanks for registering with us.<br/>"
                                                     + "Please confirm your tutor account by clicking <a href=\"" + callbackUrl + "\">" + callbackUrl + "</a><br/><br/>"
                                                     + "Regards, <br/><a href='http://instanttutors.org/' target='_blank'>Instant Tutors Team</a>");

                    //await EmailSender.SendEmailAsync("Confirm your account", "Hi " + model.FirstName + ",<br/><br/>"
                    //    + "Thanks for registering with us.<br/>"
                    //    + "Please confirm your student account by clicking <a href=\"" + callbackUrl + "\">" + callbackUrl + "</a><br/><br/>"
                    //    + "Regards, <br/><a href='http://instanttutors.org/' target='_blank'>Instant Tutors @" + DateTime.Now.Year + "</a>", user.Email, true);

                    try
                    {
                        var _subject = "New Tutor Signup | instanttutors.org";
                        var _body    = "<h5>New Tutor Signup</h5>" + ",<br/><br/>"
                                       + "<b>Fullname:</b> " + model.FirstName + " " + model.LastName + "<br/>"
                                       + "<b>Email Address:</b> " + model.Email + "<br/>"
                                       + "<b>Mobile:</b> " + model.Mobile + "<br/><br/>"
                                       + "<a href='http://instanttutors.org/' target='_blank'>Instant Tutors</a> @ " + DateTime.Now.Year;

                        await EmailSender.SendEmailAsync(_subject, _body);

                        await SMSSender.SMSSenderAsync("Thanks! Please verify your tutor a/c " + callbackUrl + " <br>Instant Tutors Team", user.PhoneNumber);

                        await SMSSender.SMSSenderAsync("New Tutor Registration - Name: " + user.FirstName + " " + user.LastName + ", M: " + user.PhoneNumber + ", Email: " + user.Email);
                    }
                    catch { }

                    ModelState.Clear();
                    ViewBag.success = "<ul><li><p style='color:green'>Successfully registered!! An email has been sent to your email address, Please verify.</p></li></ul>";
                    return(View(model));
                }
                AddErrors(result);
            }
            //var error = ModelState.FirstOrDefault(x => x.Value.Errors.Count > 0).Value.Errors.First().ErrorMessage;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }