github.com/cs3org/reva/v2@v2.27.7/pkg/siteacc/account/login/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 login 20 21 const tplJavaScript = ` 22 function verifyForm(formData, requirePassword = true) { 23 if (formData.getTrimmed("email") == "") { 24 setState(STATE_ERROR, "Please enter your email address.", "form", "email", true); 25 return false; 26 } 27 28 if (requirePassword) { 29 if (formData.get("password") == "") { 30 setState(STATE_ERROR, "Please enter your password.", "form", "password", true); 31 return false; 32 } 33 } 34 35 return true; 36 } 37 38 function handleAction(action) { 39 const formData = new FormData(document.querySelector("form")); 40 if (!verifyForm(formData)) { 41 return; 42 } 43 44 setState(STATE_STATUS, "Logging in... this should only take a moment.", "form", null, false); 45 46 var xhr = new XMLHttpRequest(); 47 xhr.open("POST", "{{getServerAddress}}/" + action); 48 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 49 50 xhr.onload = function() { 51 if (this.status == 200) { 52 setState(STATE_SUCCESS, "Your login was successful! Redirecting..."); 53 window.location.replace("{{getServerAddress}}/account/?path=manage"); 54 } else { 55 var resp = JSON.parse(this.responseText); 56 setState(STATE_ERROR, "An error occurred while trying to login your account:<br><em>" + resp.error + "</em>", "form", null, true); 57 } 58 } 59 60 var postData = { 61 "email": formData.getTrimmed("email"), 62 "password": { 63 "value": formData.get("password") 64 } 65 }; 66 67 xhr.send(JSON.stringify(postData)); 68 } 69 70 function handleResetPassword() { 71 const formData = new FormData(document.querySelector("form")); 72 if (!verifyForm(formData, false)) { 73 return; 74 } 75 76 setState(STATE_STATUS, "Resetting password... this should only take a moment.", "form", null, false); 77 78 var xhr = new XMLHttpRequest(); 79 xhr.open("POST", "{{getServerAddress}}/reset-password"); 80 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 81 82 xhr.onload = function() { 83 if (this.status == 200) { 84 setState(STATE_SUCCESS, "Your password was successfully reset! Please check your inbox for your new password.", "form", null, true); 85 } else { 86 var resp = JSON.parse(this.responseText); 87 setState(STATE_ERROR, "An error occurred while trying to reset your password:<br><em>" + resp.error + "</em>", "form", null, true); 88 } 89 } 90 91 var postData = { 92 "email": formData.get("email") 93 }; 94 95 xhr.send(JSON.stringify(postData)); 96 } 97 ` 98 99 const tplStyleSheet = ` 100 html * { 101 font-family: arial !important; 102 } 103 104 .mandatory { 105 color: red; 106 font-weight: bold; 107 } 108 ` 109 110 const tplBody = ` 111 <div> 112 <p>Login to your ScienceMesh Site Administrator Account using the form below.</p> 113 </div> 114 <div> </div> 115 <div> 116 <form id="form" method="POST" class="box container-inline" style="width: 100%;" onSubmit="handleAction('login'); return false;"> 117 <div style="grid-row: 1;"><label for="email">Email address: <span class="mandatory">*</span></label></div> 118 <div style="grid-row: 2;"><input type="text" id="email" name="email" placeholder="me@example.com"/></div> 119 <div style="grid-row: 1;"><label for="password">Password: <span class="mandatory">*</span></label></div> 120 <div style="grid-row: 2;"><input type="password" id="password" name="password"/></div> 121 <div style="grid-row: 3; grid-column: 2; font-style: italic; font-size: 0.8em;"> 122 Forgot your password? Click <a href="#" onClick="handleResetPassword();">here</a> to reset it. 123 </div> 124 125 <div style="grid-row: 4; align-self: center;"> 126 Fields marked with <span class="mandatory">*</span> are mandatory. 127 </div> 128 <div style="grid-row: 4; grid-column: 2; text-align: right;"> 129 <button type="reset">Reset</button> 130 <button type="submit" style="font-weight: bold;">Login</button> 131 </div> 132 </form> 133 </div> 134 <div> 135 <p>Don't' have an account yet? Register <a href="{{getServerAddress}}/account/?path=register">here</a>.</p> 136 </div> 137 `