github.com/cs3org/reva/v2@v2.27.7/pkg/siteacc/account/site/template.go (about) 1 // Copyright 2018-2020 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package site 20 21 const tplJavaScript = ` 22 function verifyForm(formData) { 23 if (formData.getTrimmed("clientID") == "") { 24 setState(STATE_ERROR, "Please enter the name of the test user.", "form", "clientID", true); 25 return false; 26 } 27 28 if (formData.get("secret") == "") { 29 setState(STATE_ERROR, "Please enter the password of the test user.", "form", "secret", true); 30 return false; 31 } 32 33 return true; 34 } 35 36 function handleAction(action) { 37 const formData = new FormData(document.querySelector("form")); 38 if (!verifyForm(formData)) { 39 return; 40 } 41 42 setState(STATE_STATUS, "Configuring site... this should only take a moment.", "form", null, false); 43 44 var xhr = new XMLHttpRequest(); 45 xhr.open("POST", "{{getServerAddress}}/" + action); 46 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 47 48 xhr.onload = function() { 49 if (this.status == 200) { 50 setState(STATE_SUCCESS, "Your site was successfully configured!", "form", null, true); 51 } else { 52 var resp = JSON.parse(this.responseText); 53 setState(STATE_ERROR, "An error occurred while trying to configure your site:<br><em>" + resp.error + "</em>", "form", null, true); 54 } 55 } 56 57 var postData = { 58 "config": { 59 "testClientCredentials": { 60 "id": formData.getTrimmed("clientID"), 61 "secret": formData.get("secret") 62 } 63 } 64 }; 65 66 xhr.send(JSON.stringify(postData)); 67 } 68 ` 69 70 const tplStyleSheet = ` 71 html * { 72 font-family: arial !important; 73 } 74 75 input[type="checkbox"] { 76 width: auto; 77 } 78 79 .mandatory { 80 color: red; 81 font-weight: bold; 82 } 83 ` 84 85 const tplBody = ` 86 <div> 87 <p>Configure your ScienceMesh Site below. <em>These settings affect your entire site and not just your account.</em></p> 88 </div> 89 <div> </div> 90 <div> 91 <form id="form" method="POST" class="box container-inline" style="width: 100%;" onSubmit="handleAction('site-configure?invoker=user'); return false;"> 92 <div style="grid-row: 1; grid-column: 1 / span 2;"> 93 <h3>Test user settings</h3> 94 <p>In order to perform automated tests on your site, a test user has to be configured below. Please note that the user <em>has to exist in your Reva instance</em>! If you do not have a user for automated tests in your instance yet, create one first.</p> 95 <hr> 96 </div> 97 98 <div style="grid-row: 2;"><label for="clientID">User name: <span class="mandatory">*</span></label></div> 99 <div style="grid-row: 3;"><input type="text" id="clientID" name="clientID" placeholder="User name" value="{{.Site.Config.TestClientCredentials.ID}}"/></div> 100 <div style="grid-row: 2;"><label for="secret">Password: <span class="mandatory">*</span></label></div> 101 <div style="grid-row: 3;"><input type="password" id="secret" name="secret" placeholder="Password" value="{{.Site.Config.TestClientCredentials.Secret}}"/></div> 102 103 <div style="grid-row: 4;"> </div> 104 105 <div style="grid-row: 5; align-self: center;"> 106 Fields marked with <span class="mandatory">*</span> are mandatory. 107 </div> 108 <div style="grid-row: 5; grid-column: 2; text-align: right;"> 109 <button type="reset">Reset</button> 110 <button type="submit" style="font-weight: bold;">Save</button> 111 </div> 112 </form> 113 </div> 114 <div> 115 <p>Go <a href="{{getServerAddress}}/account/?path=manage">back</a> to the main account page.</p> 116 </div> 117 `