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); }
public ActionResult AuthenticationInviteCode(AuthenticationInviteCodeModel model) { if (!ModelState.IsValid) { return(this.View(model)); } if (string.IsNullOrEmpty(model.AuthenticationCode)) { ModelState.AddModelError("AuthenticationCode", "The code is required"); } else { var invitationLogic = new InvitationUILogic(); var invitation = invitationLogic.GetInvitationModelByModelId(model.AuthenticationCode); if (invitation == null) { ModelState.AddModelError("AuthenticationCode", "Code is invalid"); } else { if (invitation.Tenancy.Equals(TenantManager.CurrentTenancy, StringComparison.OrdinalIgnoreCase) || !User.Identity.IsAuthenticated) { return(this.RedirectToRoute( "Default", new { tenant = invitation.Tenancy, controller = "OwnerInvitation", areaName = Areas.UserManagementUI.AreaPortableName.AreaName, action = "AcceptInvitation", id = invitation.AuthorizationCode //.UrlEncodedCode })); } FormsAuthentication.SignOut(); this.SetAuthCookie(User.Identity.Name, false, invitation.Tenancy); return(this.RedirectToRoute( "Default", new { tenant = invitation.Tenancy, controller = "OwnerInvitation", areaName = Areas.UserManagementUI.AreaPortableName.AreaName, action = "AcceptInvitation", id = invitation.AuthorizationCode //.UrlEncodedCode })); } } return(this.View(model)); }
public OwnerInvitationController() { _invitationUILogic = new InvitationUILogic(); _systemOwnerId = _invitationUILogic.GetSuperAdminId(); _log = ClassLogger.Create(this.GetType()); _applicationAlert = Catalog.Factory.Resolve <IApplicationAlert>(); _command = new List <string> { "Create", "Edit", "Details", "Delete", "Sent Email" }; _command1 = new List <string> { "Edit", "Details", "Delete", "Sent Email" }; }
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); }
public ActionResult Register(RegisterModel model) { try { if (ModelState.IsValid) { //begin var invitationUILogic = new InvitationUILogic(); var invitationModel = invitationUILogic.GetInvitationModelByModelId(model.AuthenticationCode); if (invitationModel == null && !TenantManager.CurrentTenancy.Equals( Tenants.SuperAdmin, StringComparison.InvariantCultureIgnoreCase)) { ModelState.AddModelError("AuthenticationCode", "Code is invalid"); ViewBag.ErrorMessage = "Code is invalid"; return(View(model)); } if (invitationModel != null) { ActionResult redirectToRoute; if (this.RedirectToCorrectTenancy(invitationModel, out redirectToRoute)) { return(redirectToRoute); } if (!invitationModel.SentTo.Equals(model.Email, StringComparison.InvariantCultureIgnoreCase)) { this.ModelState.AddModelError("Email", "Email do not equals invitation's email"); ViewBag.ErrorMessage = "Email do not equals invitation's email"; return(View(model)); } } //end var invitation = this.Session["Invitation"] as OwnerInvitationModel ?? invitationModel; Server.MapPath(DefaultAvatarLocation); MembershipCreateStatus createStatus; //membership created and log automatically if (CreateMembershipUser(model, invitationUILogic.ModelToEntity(invitation), out createStatus)) { Session["Invitation"] = null; object passcode; string code = null; if (TempData.TryGetValue("passcode", out passcode)) { code = passcode.ToString(); } //if (code != null) if (!string.IsNullOrEmpty(code)) { TempData.Remove("passcode"); var passCodeModel = new TakeOwnerShipModel { PassCode = code }; if (_accountBusinessLogic.AddRoleToUser(passCodeModel, User.Identity.Name)) { var user = User as ApplicationUser; if (user != null && user.Tenancy.Equals(Tenants.SuperAdmin, StringComparison.InvariantCultureIgnoreCase)) { return(RedirectToAction("Index", "OwnerInvitation")); } ActionResult redirectToRoute; return(this.LoginPostValidations(out redirectToRoute) ? redirectToRoute : RedirectAfterLogin(null)); } } } this.ModelState.AddModelError(string.Empty, ErrorCodeToString(createStatus)); } } catch (Exception ex) { if (ExceptionHandler.Manage(ex, this, Layer.UILogic)) { this.ModelState.AddModelError(string.Empty, ex.Message); ViewBag.ErrorMessage = ex.Message; } else { if (ex.InnerException != null) { _log.ErrorFormat("{0} \n Inner Exception: {1}", ex, ex.InnerException); } else { _log.ErrorFormat("An exception occurred with the following message: {0}", ex.Message); } _applicationAlert.RaiseAlert(ApplicationAlertKind.System, ex.TraceInformation()); const string errorMessage = "An error occurred while processing your request. Please refresh the page. The error have been logged."; this.ModelState.AddModelError(string.Empty, errorMessage); ViewBag.ErrorMessage = errorMessage; } return(View(model)); } // If we got this far, something failed, redisplay form //return View(model);S ActionResult routeToRedirect; return(this.LoginPostValidations(out routeToRedirect) ? routeToRedirect : RedirectAfterLogin(null)); //return RedirectToAction("Index", "OwnerInvitation"); }