Exemplo n.º 1
0
        public async Task <ActionResult> Create([Bind(Include = "Username,Email,Organization")] InviteViewModel invite)
        {
            var Organizations = await db.Organizations.ToListAsync();

            if (ModelState.IsValid)
            {
                var Organization = Organizations.Where(x => x.Key == invite.Organization).FirstOrDefault();

                if (Organization != null)
                {
                    var Name = invite.Username + "@" + Organization.Domain;

                    if (await CheckUsername(Name))
                    {
                        var Auth = Extensions.GetUniqueKey(7) + "-" + Extensions.GetUniqueKey(24);

                        db.Invites.Add(new Invite()
                        {
                            Email        = invite.Email,
                            Password     = Auth,
                            Username     = Name,
                            Organization = Organization,
                            Role         = User.IsInRole(Roles.AppAdmin) ? Roles.SysAdmin : Roles.AppUser
                        });

                        await db.SaveChangesAsync();

                        Hangfire.BackgroundJob.Enqueue(() => PostalMail.SendUserInvite(invite.Email, invite.Username, "Organization Administrator", Organization.Name, Request.Url.GetLeftPart(UriPartial.Authority) + "/Invites/Verify/" + Auth));

                        TempData.SetSuccess("Invite has been successfully sent to " + invite.Email);

                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("Username", "Specified user name is already taken.");
                    }
                }
                else
                {
                    ModelState.AddModelError("Organization", "Selected organization is not found.");
                }
            }

            invite.Organizations = Organizations.ToSelectList("Name", "- Organizations -", SelectedField: invite.Organization);

            SetInfo();
            return(View(invite));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Resend(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var Invite = await db.Invites.Include("Organization").SingleAsync(x => x.Key == id);

            if (Invite == null)
            {
                return(HttpNotFound());
            }

            Hangfire.BackgroundJob.Enqueue(() => PostalMail.SendUserInvite(Invite.Email, Invite.Username, "Organization Administrator", Invite.Organization.Name, Request.Url.GetLeftPart(UriPartial.Authority) + "/Invites/Verify/" + Invite.Password));

            TempData.SetSuccess("Invite has been successfully resent to " + Invite.Email);

            SetInfo();

            return(View("Details", Invite));
        }