public ActionResult ConfirmationScreen(string token) { try { // Get model LicenseConfirmModel model = _licenseVerification.GetConfirmModel(token, LoggedInUser); // Return appropriate view switch (model.Type) { case OrganisationLicenseType.FromTemplate: return(View("ConfirmationScreen", model)); case OrganisationLicenseType.Custom: return(View("CustomLicenseVerification", model)); default: throw new BaseException("Unknown license type."); } } catch (BaseException ex) { // Log action _auditLog.Log(AuditStream.LegalAgreements, "Confirmation Failed: ", new { id = LoggedInUser.ID, email = LoggedInUser.Email }, new { error = ex.Message, remote_ip = Request.UserHostAddress, browser = Request.Browser.Browser }); throw; } }
public LicenseConfirmModel GetLicenseForProviderAndSchema(int providerId, int schemaId, LoggedInUserDetails user) { try { CheckForLegalOfficer(user); } catch (BaseException ex) { // TODO: send request off to the consumers legal officer return(null); } var license = _orgLicenses.FirstOrDefault(i => i.ID == providerId && i.DataSchemaID == schemaId); // Get organisation details var organization = _organisations.FirstOrDefault(i => i.ID == user.Organization.ID); // Determine license type var type = GetType(license); // Get content for license var licenseContent = GetLicenseContent(license, organization.ID, type); // Setup result var result = new LicenseConfirmModel { OrganizationName = organization.Name, ID = license.ID, LicenseContent = licenseContent, Type = type, IsProvider = false }; return(result); }
public LicenseConfirmModel GetConfirmModel(string token, LoggedInUserDetails user) { OrganizationLicense license = null; LicenseApprovalRequest request = null; try { // Check access _security.CheckBasicAccess(user); // Process token var tokenInfo = _tokens.ParseLicenseVerificationToken(token); // Get license license = _orgLicenses.FirstOrDefault(i => i.ID == tokenInfo.ID.Value); // Get request request = _verificationRequests.FirstOrDefault(i => i.Token == tokenInfo.Token); // Check whether token exists if (request == null) { throw new BaseException("Access denied."); } // Check whether token belongs to user if (request.SentTo != user.ID.Value) { request.ExpiresAt = GetDate; _verificationRequests.Update(request); throw new BaseException("Access denied."); } // Check whether token expired if (request.ExpiresAt != tokenInfo.TokenExpire || request.ExpiresAt < DateTime.Now) { throw new BaseException( "Approval link is expired."); } // Check whether user is Legal officer for organisation CheckForLegalOfficer(user); // Check whether organisation is active if (!user.Organization.IsActive) { throw new BaseException( "Your organization is inactive. Please check if your organization has approved Legal Officer. For more details contact DataLinker team."); } // Check whether licese is pending approval if (license.Status != (int)PublishStatus.PendingApproval) { throw new BaseException("This license is not pending approval."); } // Get organisation details var organization = _organisations.FirstOrDefault(i => i.ID == user.Organization.ID); // Determine license type var type = GetType(license); // Get content for license var licenseContent = GetLicenseContent(license, organization.ID, type); // Setup result var result = new LicenseConfirmModel { OrganizationName = organization.Name, ID = license.ID, LicenseContent = licenseContent, Type = type, IsProvider = license.ProviderEndpointID != 0 }; // Return result return(result); } catch (BaseException) { // Set license status to draft if (license != null && license.Status == (int)PublishStatus.PendingApproval) { license.Status = (int)PublishStatus.Draft; _orgLicenses.Update(license); } throw; } finally { // Always expire request if (request != null) { request.ExpiresAt = GetDate; _verificationRequests.Update(request); } } }