Beispiel #1
0
        public Invitation ModelToEntity(OwnerInvitationModel model)
        {
            if (model == null)
            {
                return(null);
            }

            ApplicationUser acceptingAppUser = null;

            if (!string.IsNullOrEmpty(model.AcceptingUserId))
            {
                var id            = model.AcceptingUserId.Split('/').Last();
                var guid          = Guid.Parse(id);
                var acceptingUser = new UserBusinessLogic().GetUserEntityById(guid);
                acceptingAppUser = acceptingUser.AppUser;
            }

            return(new Invitation
            {
                Id = model.Id,
                SentTo = model.SentTo,
                AuthorizationCode =
                    new InvitationAuthCode {
                    EmailedTo = model.SentTo, InvitingTenancy = model.InvitingTenancy
                },
                DateSent = DateTime.UtcNow,
                ExpirationTime = model.ExpirationTime,
                ResentTimes = 0,
                Status = model.Status,
                Tenancy = model.Tenancy,
                Role = model.Role,
                InvitingTenant = model.InvitingTenancy,
                AcceptingUser = acceptingAppUser
            });
        }
Beispiel #2
0
        public void SendInvitation(
            User user, string newTenancy, string invitingTenancy, Uri url, ApplicationUser applicationUser)
        {
            var invitation = new OwnerInvitationModel
            {
                Tenancy         = newTenancy,
                SentTo          = user.Email,
                ExpirationTime  = user.ExpirationTime,
                Role            = user.Roles.First(),
                Status          = InvitationStatus.New,
                InvitingTenancy = invitingTenancy
            };

            var ic           = new InvitationUILogic();
            var invitationDb = ic.CreateDBInvitation(invitation, newTenancy, applicationUser);

            user.Id = new Guid(invitationDb.AcceptingUserId.Split('/').Last());

            if (string.IsNullOrEmpty(user.Username))
            {
                user.Username = user.Email;
            }

            //once invitation is sent it creates the local tenant
            ic.SendInvitationEmail(user.Email, url, applicationUser, newTenancy);
        }
Beispiel #3
0
        public ActionResult Delete(OwnerInvitationModel ownerInvitationModel)
        {
            var  id = ownerInvitationModel.Id.ToString();
            Guid invitationId;

            if (!Guid.TryParse(id, out invitationId))
            {
                return(this.View());
            }

            var user = User as ApplicationUser;

            try
            {
                var success = _invitationUILogic.Remove(invitationId);
                if (success)
                {
                    return(this.RedirectToAction("Index"));
                }
            }
            catch (Exception exception)
            {
                _log.ErrorFormat(
                    "Current User: {0} - An exception occurred with the following message: {1}",
                    user.UserName,
                    exception.Message);
                _applicationAlert.RaiseAlert(ApplicationAlertKind.System, exception.TraceInformation());

                var im = this._invitationUILogic.GetInvitationsModelById(invitationId);
                return(this.View(im));
            }

            return(this.RedirectToAction("Index"));
        }
Beispiel #4
0
        private void LogoutUser(OwnerInvitationModel invitationModel)
        {
            //logout current user
            FormsAuthentication.SignOut();
            this.HttpContext.User = new GenericPrincipal(new GenericIdentity(string.Empty), new string[] {});

            // add user, redirect to registration form
            this.Session["Invitation"] = invitationModel;
        }
Beispiel #5
0
        internal Invitation CreateDBInvitation(OwnerInvitationModel model, string tenancy, ApplicationUser user)
        {
            var expirationTime = DateTime.UtcNow.AddDays(model.ExpirationTime);

            model.Status = InvitationStatus.New;

            var invitation = this.CreateInvitationEntityFromModel(model, expirationTime, user);

            return(invitationBusinessLogic.CreateInvitation(invitation, tenancy));
        }
Beispiel #6
0
        internal Invitation CreateDBInvitation(OwnerInvitationModel model, ApplicationUser creatorPrincipal)
        {
            var expirationTime = DateTime.UtcNow.AddDays(model.ExpirationTime);

            model.Status = InvitationStatus.New;

            var invitation = this.CreateInvitationEntityFromModel(model, expirationTime, creatorPrincipal);

            return(invitationBusinessLogic.CreateInvitation(invitation));
        }
Beispiel #7
0
        public ActionResult Create(OwnerInvitationModel newModel)
        {
            var user = User as ApplicationUser;

            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", new { reload = true }));
                }

                var emailNotExist = _invitationUILogic.NotFoundUserWithEmail(newModel.SentTo);
                if (emailNotExist)
                {
                    _invitationUILogic.CreateInvitation(newModel, Request.Url, user);

                    Thread.Sleep(100);
                    //an issue when adding new invitation it do not appear on the index after adding
                    return(RedirectToAction("Index"));
                }

                TempData.Add("CurrentInvitation", newModel);

                TempData.Remove("MessageError");
                TempData.Add("MessageError", "Email already invited, try with another email");

                ModelState.AddModelError("SentTo", "Email already invited, try with another email");
                return(RedirectToAction("Index", new { reload = true }));
            }
            catch (Exception ex)
            {
                var errorMessage = "Failure to send the email, please check the SMTP configuration";
                if (ExceptionHandler.Manage(ex, this, Layer.UILogic))
                {
                    errorMessage = ex.Message;
                }

                if (user != null)
                {
                    _log.ErrorFormat("Current User: {0} - An exception occurred with the following message: {1}",
                                     user.UserName, ex.Message);
                }

                _applicationAlert.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation());
                this.ModelState.AddModelError("Tenancy", errorMessage);

                TempData.Remove("MessageError");
                TempData.Add("MessageError", errorMessage);

                TempData.Remove("CurrentInvitation");
                TempData.Add("CurrentInvitation", newModel);

                return(RedirectToAction("Index", new { reload = true }));
            }
        }
Beispiel #8
0
        internal void CreateInvitation(OwnerInvitationModel newModel, Uri requestUrl, ApplicationUser user = null)
        {
            newModel.Role            = "TenantOwner";
            newModel.InvitingTenancy = Tenants.SuperAdmin;

            invitationBusinessLogic.TestSmtpServer();

            //this controller always use views to send invitation to TenantOwner from the SuperAdmin
            var invitation = this.CreateDBInvitation(newModel, user);

            this.SendInvitationId(invitation.Id, requestUrl, invitation.AcceptingUser);
        }
        private bool RedirectToCorrectTenancy(OwnerInvitationModel invitation, out ActionResult redirectToRoute)
        {
            redirectToRoute = null;

            var newTenancy = invitation.Tenancy;

            if (!TenantManager.CurrentTenancy.Equals(newTenancy, StringComparison.InvariantCultureIgnoreCase))
            {
                redirectToRoute = this.RedirectToRoute(
                    "Default",
                    new
                {
                    tenant     = newTenancy,
                    controller = this.ControllerContext.RouteData.Values["controller"].ToString(),
                    action     = this.ControllerContext.RouteData.Values["action"].ToString(),
                    id         = invitation.AuthorizationCode //.UrlEncodedCode
                });
                return(true);
            }
            return(false);
        }
Beispiel #10
0
        public ActionResult Edit(OwnerInvitationModel model)
        {
            var user = User as ApplicationUser;

            try
            {
                if (ModelState.IsValid)
                {
                    _invitationUILogic.UpdateInvitation(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                var errorMessage = "Failure to update an invitation, please check the SMTP configuration";
                if (ExceptionHandler.Manage(ex, this, Layer.UILogic))
                {
                    errorMessage = ex.Message;
                }

                if (user != null)
                {
                    _log.ErrorFormat("Current User: {0} - An exception occurred with the following message: {1}",
                                     user.UserName, ex.Message);
                }

                _applicationAlert.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation());
                this.ModelState.AddModelError("Tenancy", errorMessage);

                TempData.Remove("MessageError");
                TempData.Add("MessageError", errorMessage);

                TempData.Remove("CurrentInvitation");
                TempData.Add("CurrentInvitation", model);

                return(RedirectToAction("Index", new { reload = true }));
            }
        }
Beispiel #11
0
        public Invitation CreateInvitationEntityFromModel(OwnerInvitationModel model, DateTime expirationTime, ApplicationUser creatorPrincipal)
        {
            var email       = model.SentTo;
            var userInvited = userBusinessLogic.GetByEmail(email);

            if (userInvited == null)
            {
                userInvited = new Lok.Unik.ModelCommon.Client.User
                {
                    AppUser =
                        new ApplicationUser
                    {
                        Tenancy      = model.Tenancy,
                        ContactEmail = model.SentTo,
                        Status       = UserStatus.Invited,
                        DateCreated  = DateTime.UtcNow,
                        PrincipalId  = string.Format("formsauthentication/{0}", Guid.NewGuid())
                    }
                };

                userBusinessLogic.CreateNewUser(userInvited, creatorPrincipal);
            }

            var list        = ContextRegistry.ContextsOf("Principal");
            var principalId = list.Single().LocalPath.TrimStart('/');

            var invitation = this.ModelToEntity(model);

            invitation.AcceptingUser = userInvited.AppUser;
            if (invitation.AuthorizationCode != null)
            {
                invitation.AuthorizationCode.ExpirationTime = expirationTime;
            }

            invitation.InvitingUserId = principalId;

            return(invitation);
        }
Beispiel #12
0
        public void SendInvitation(User user, string currentTenancy, Uri url, ApplicationUser currentUser)
        {
            var invitation = new OwnerInvitationModel
            {
                Tenancy         = currentTenancy,
                SentTo          = user.Email,
                ExpirationTime  = user.ExpirationTime,
                Role            = user.Roles.First(),
                Status          = InvitationStatus.New,
                InvitingTenancy = currentTenancy
            };

            var ic           = new InvitationUILogic();
            var invitationDb = ic.CreateDBInvitation(invitation, currentUser);

            user.Id = new Guid(invitationDb.AcceptingUserId.Split('/').Last());

            if (string.IsNullOrEmpty(user.Username))
            {
                user.Username = user.Email;
            }

            var success = ic.SendInvitationEmail(user.Email, url, currentUser);
        }
Beispiel #13
0
 internal void InvitationRejected(OwnerInvitationModel invitation)
 {
     invitationBusinessLogic.InvitationRejected(this.ModelToEntity(invitation));
 }
Beispiel #14
0
 private string GetEmailContent(OwnerInvitationModel invitation, Uri uri, string emailTemplateName)
 {
     return(invitationBusinessLogic.GetEmailContent(invitation.SentTo, invitation.Tenancy, invitation.AuthorizationCode, uri, emailTemplateName));
 }
Beispiel #15
0
 public void UpdateInvitation(OwnerInvitationModel model)
 {
     invitationBusinessLogic.UpdateInvitation(model.SentTo, model.ExpirationTime, model.Tenancy);
 }
Beispiel #16
0
 public bool UpdateInvitation(OwnerInvitationModel model, string appUserId)
 {
     return(invitationBusinessLogic.UpdateInvitation(this.ModelToEntity(model), appUserId));
 }