예제 #1
0
        public ActionResult Register(CreateAccountViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            // Check if the user exists.
            if (this.accountLogics.DoesUserExist(model.UserName))
            {
                this.TempData["Error"] = "Account already exists.";
                return(this.View(model));
            }

            // Set the link to the home page
            if (this.homeLink == null)
            {
                var urlHelper = new UrlHelper(ControllerContext.RequestContext);
                this.homeLink = new Uri(urlHelper.Action("Index", "Web", null, "http"));
            }

            // Create the account
            var createdUser = this.accountLogics.CreateAccount(model, this.homeLink);

            // If account creation fails, show an error.
            if (createdUser == null)
            {
                this.TempData["Error"] = "Unable to create account. Please try again.";
                return(this.View(model));
            }

            // Remove the invite
            InviteLogics inviteLogics = new InviteLogics();

            inviteLogics.CancelInvite(model.InviteId);

            this.SetAuthenticationTicket(createdUser.Id, ((int)model.UserType).ToString());

            return(this.RedirectToAction("Index", "Web"));
        }
예제 #2
0
        public ActionResult Register(int?inviteId, string token)
        {
            if (inviteId == null)
            {
                ViewBag.ValidInvite = false;
            }
            else
            {
                // Validate the invite.
                var inviteLogics = new InviteLogics();
                var validInvite  = inviteLogics.ValidateInvite(inviteId.GetValueOrDefault(0), token);
                ViewBag.ValidInvite = validInvite != null;

                if (ViewBag.ValidInvite)
                {
                    // Preset the form fields from the invite information.
                    var viewModel = new CreateAccountViewModel
                    {
                        UserName   = validInvite.InviteeEmailAddress,
                        UserType   = validInvite.UserRoleType,
                        InviteId   = inviteId.GetValueOrDefault(0),
                        ProviderId = validInvite.ServiceProviderId
                    };

                    return(this.View(viewModel));
                }
                else
                {
                    // Invalid invite - shown an error
                    this.TempData["Error"] = "You invite to create an account is invaild, please contact your adminstrator for a new invitation.";
                    return(View());
                }
            }

            // No invite id was given.
            this.TempData["Error"] = "You must be invited to create an account.  Please contact your adminstrator for an invitation.";
            return(View());
        }
예제 #3
0
        public void TestInitialize()
        {
            this.logics = new InviteLogics();

            this.guid = Guid.NewGuid().ToString();

            this.sampleInvite = new Invite
            {
                ID         = 1,
                CreatedAt  = DateTime.Now,
                CreatorID  = 5,
                Email      = "*****@*****.**",
                RoleTypeID = 1,
                Token      = this.guid
            };

            this.sampleInviteViewModel = new InviteViewModel
            {
                Id                  = 0,
                DateSent            = DateTime.Now,
                InviteeEmailAddress = "*****@*****.**",
                UserRoleType        = UserRoleType.Admin
            };
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InviteController"/> class for testing.
 /// </summary>
 /// <param name="registerForTest"> The register for test. </param>
 public InviteController(Uri registerForTest)
 {
     this.inviteLogics = new InviteLogics();
     this.registerLink = registerForTest;
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InviteController"/> class.
 /// </summary>
 public InviteController()
 {
     this.inviteLogics = new InviteLogics();
     this.registerLink = null;
 }