private async Task <string> GetMemberNamesAsync(string Email)
        {
            var user = await UserManager.FindByEmailAsync(Email);

            var SchemeName = PensionSetup.GetSchemeNameAsync(user.SponsorNumber);
            var Member     = PensionSetup.GetMemberDetailsAsync(SchemeName, user.MemberNumber);

            return(Member.First_Name + ' ' + Member.Last_Name);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Status = 400, Message = "There is a problem with your input. Make sure you follow all password rules and all fields are valid." }));
            }

            string SponsorNumber = PensionSetup.GetSchemeNameAsync(model.SponsorNumber);

            if (SponsorNumber == null)
            {
                //ModelState.AddModelError("invalid_grant", "Sponsor Number does not exists");
                return(Json(new { Status = 400, Message = "Sponsor Number does not exists" }));
            }

            string MemberNumber = PensionSetup.GetMemberNumberAsync(model.StaffNumber, SponsorNumber);

            if (MemberNumber == null)
            {
                //ModelState.AddModelError("invalid_grant", "Staff Number does not exists");
                return(Json(new { Status = 400, Message = "Staff Number does not exists" }));
            }

            //Check if member has email
            var Member = PensionSetup.GetMemberDetailsAsync(SponsorNumber, MemberNumber);

            if (Member.E_Mail == null)
            {
                //ModelState.AddModelError("invalid_grant", "We didn't find any email associated to your profile, please contact your system administrator");
                return(Json(new { Status = 400, Message = "We didn't find any email associated to your profile, please contact your system administrator" }));
            }
            var user = new ApplicationUser {
                SponsorNumber = model.SponsorNumber, MemberNumber = MemberNumber, UserName = Member.E_Mail, Email = Member.E_Mail
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }
            //Send email
            string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

            return(Json(new { Status = 200, Message = "We've sent an email to " + Member.E_Mail + ". Open your mail box to confirm your account.", Link = callbackUrl }));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (CheckIfSponsorNumberExistsAsync(model.SponsorNumber).Equals(true))
                {
                    //Staff number equals model.MemberNumber
                    string StaffNumber = model.MemberNumber;
                    if (CheckIfMemberNumberExistsAsync(StaffNumber, model.SponsorNumber).Equals(true))
                    {
                        string SchemeName   = PensionSetup.GetSchemeNameAsync(model.SponsorNumber);
                        string MemberNumber = PensionSetup.GetMemberNumberAsync(StaffNumber, model.SponsorNumber);

                        if (UserManager.Users.Where(x => x.SponsorNumber == model.SponsorNumber && x.MemberNumber == MemberNumber).Any())
                        {
                            ModelState.AddModelError("MemberRegistered", "Member (" + model.SponsorNumber + " & " + model.MemberNumber + ") is already registered");
                            return(View(model));
                        }
                        else
                        {
                            if (model.Email == null)
                            {
                                //Try to find one from member details
                                var    Member = PensionSetup.GetMemberDetailsAsync(SchemeName, MemberNumber);
                                string Email  = Member.E_Mail;
                                if (Email == null)
                                {
                                    //ViewBag.EmailIsEmpty = true;
                                    ModelState.AddModelError("EmailIsEmpty", "We didn't find any email associated to your profile, please contact your system administrator");
                                    return(View(model));
                                }
                                model.Email = Email;
                            }
                            var user = new ApplicationUser {
                                SponsorNumber = model.SponsorNumber, MemberNumber = MemberNumber, UserName = model.Email, Email = model.Email
                            };
                            var result = await UserManager.CreateAsync(user, model.Password);

                            if (result.Succeeded)
                            {
                                //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

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

                                ViewBag.Message = "We've sent an email to " + model.Email + ". Check in 5-10 minutes to confirm your account.";

                                return(View("Info"));
                            }
                            //ViewBag.EmailIsEmpty = true;
                            AddErrors(result);
                        }
                    }
                    else
                    {
                        if (ViewBag.errorMessage != null)
                        {
                            return(View("Error"));
                        }

                        ModelState.AddModelError("MemberExists", "Member Number does not exists in " + model.SponsorNumber);
                        return(View(model));
                    }
                }
                else
                {
                    if (ViewBag.errorMessage != null)
                    {
                        return(View("Error"));
                    }

                    ModelState.AddModelError("SponsorExists", "Sponsor Number does not exists");
                    return(View(model));
                }
            }

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