github.com/cs3org/reva/v2@v2.27.7/pkg/siteacc/account/registration/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 registration
    20  
    21  const tplJavaScript = `
    22  function verifyForm(formData) {
    23  	if (formData.getTrimmed("email") == "") {
    24  		setState(STATE_ERROR, "Please specify your email address.", "form", "email", true);
    25  		return false;
    26  	}
    27  
    28  	if (formData.getTrimmed("fname") == "") {
    29  		setState(STATE_ERROR, "Please specify your first name.", "form", "fname", true);
    30  		return false;
    31  	}
    32  
    33  	if (formData.getTrimmed("lname") == "") {
    34  		setState(STATE_ERROR, "Please specify your last name.", "form", "lname", true);	
    35  		return false;
    36  	}
    37  
    38  	if (formData.getTrimmed("site") == "") {
    39  		setState(STATE_ERROR, "Please select your ScienceMesh site.", "form", "site", true);
    40  		return false;
    41  	}
    42  
    43  	if (formData.getTrimmed("role") == "") {
    44  		setState(STATE_ERROR, "Please specify your role within your site.", "form", "role", true);
    45  		return false;
    46  	}
    47  
    48  	if (formData.get("password") == "") {
    49  		setState(STATE_ERROR, "Please set a password.", "form", "password", true);
    50  		return false;
    51  	}
    52  
    53  	if (formData.get("password2") == "") {
    54  		setState(STATE_ERROR, "Please confirm your password.", "form", "password2", true);
    55  		return false;
    56  	}
    57  
    58  	if (formData.get("password") != formData.get("password2")) {
    59  		setState(STATE_ERROR, "The entered passwords do not match.", "form", "password2", true);
    60  		return false;
    61  	}
    62  
    63  	return true;
    64  }
    65  
    66  function handleAction(action) {
    67  	const formData = new FormData(document.querySelector("form"));
    68  	if (!verifyForm(formData)) {
    69  		return;
    70  	}
    71  
    72  	setState(STATE_STATUS, "Sending registration... this should only take a moment.", "form", null, false);
    73  
    74  	var xhr = new XMLHttpRequest();
    75      xhr.open("POST", "{{getServerAddress}}/" + action);
    76      xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
    77  
    78  	xhr.onload = function() {
    79  		if (this.status == 200) {
    80  			setState(STATE_SUCCESS, "Your registration was successful! Please check your inbox for a confirmation email. You will be redirected to the login page in a few seconds (if not, click <a href='{{getServerAddress}}/account/?path=login'>here</a>).");
    81  			window.setTimeout(function() {
    82                  window.location.replace("{{getServerAddress}}/account/?path=login");
    83  			}, 3000);
    84  		} else {
    85  			var resp = JSON.parse(this.responseText);
    86  			setState(STATE_ERROR, "An error occurred while trying to register your account:<br><em>" + resp.error + "</em>", "form", null, true);
    87  		}
    88  	}
    89  
    90  	var postData = {
    91          "email": formData.getTrimmed("email"),
    92  		"title": formData.getTrimmed("title"),
    93  		"firstName": formData.getTrimmed("fname"),
    94  		"lastName": formData.getTrimmed("lname"),
    95  		"site": formData.getTrimmed("site"),
    96  		"role": formData.getTrimmed("role"),
    97  		"phoneNumber": formData.getTrimmed("phone"),
    98  		"password": {
    99  			"value": formData.get("password")
   100  		}
   101      };
   102  
   103      xhr.send(JSON.stringify(postData));
   104  }
   105  `
   106  
   107  const tplStyleSheet = `
   108  html * {
   109  	font-family: arial !important;
   110  }
   111  
   112  .mandatory {
   113  	color: red;
   114  	font-weight: bold;
   115  }
   116  `
   117  
   118  const tplBody = `
   119  <div>
   120  	<p>Fill out the form below to register for a ScienceMesh Site Administrator account. A confirmation email will be sent to you shortly after registration.</p>	
   121  </div>
   122  <div>&nbsp;</div>
   123  <div>
   124  	<form id="form" method="POST" class="box container-inline" style="width: 100%;" onSubmit="handleAction('create'); return false;">	
   125  		<div style="grid-row: 1;"><label for="email">Email address: <span class="mandatory">*</span></label></div>
   126  		<div style="grid-row: 2;"><input type="text" id="email" name="email" placeholder="me@example.com"/></div>
   127  		<div style="grid-row: 1;"><label for="site">ScienceMesh Site: <span class="mandatory">*</span></label></div>
   128  		<div style="grid-row: 2;">
   129  			<select id="site" name="site">
   130  			{{range .Sites}}
   131  			<option value="{{.ID}}">{{.Name}} | {{.FullName}}</option>
   132  			{{end}}
   133  			</select>
   134  		</div>
   135  
   136  		<div style="grid-row: 3;">&nbsp;</div>
   137  
   138  		<div style="grid-row: 4;"><label for="title">Title: <span class="mandatory">*</span></label></div>
   139  		<div style="grid-row: 5;">
   140  			<select id="title" name="title">
   141  			{{range .Titles}}
   142  			<option value="{{.}}">{{.}}.</option>
   143  			{{end}}
   144  			</select>
   145  		</div>
   146  
   147  		<div style="grid-row: 6;"><label for="fname">First name: <span class="mandatory">*</span></label></div>
   148  		<div style="grid-row: 7;"><input type="text" id="fname" name="fname"/></div>
   149  		<div style="grid-row: 6;"><label for="lname">Last name: <span class="mandatory">*</span></label></div>
   150  		<div style="grid-row: 7;"><input type="text" id="lname" name="lname"/></div>
   151  		
   152  		<div style="grid-row: 8;"><label for="role">Role: <span class="mandatory">*</span></label></div>
   153  		<div style="grid-row: 9;"><input type="text" id="role" name="role" placeholder="Site administrator"/></div>
   154  		<div style="grid-row: 8;"><label for="phone">Phone number:</label></div>
   155  		<div style="grid-row: 9;"><input type="text" id="phone" name="phone" placeholder="+49 030 123456"/></div>
   156  
   157  		<div style="grid-row: 10;">&nbsp;</div>
   158  
   159  		<div style="grid-row: 11;"><label for="password">Password: <span class="mandatory">*</span></label></div>
   160  		<div style="grid-row: 12;"><input type="password" id="password" name="password"/></div>
   161  		<div style="grid-row: 11;"><label for="password2">Confirm password: <span class="mandatory">*</span></label></div>
   162  		<div style="grid-row: 12;"><input type="password" id="password2" name="password2"/></div>
   163  
   164  		<div style="grid-row: 13; font-style: italic; font-size: 0.8em;">
   165  			The password must fulfil the following criteria:
   166  			<ul style="margin-top: 0em;">
   167  				<li>Must be at least 8 characters long</li>
   168  				<li>Must contain at least 1 lowercase letter</li>
   169  				<li>Must contain at least 1 uppercase letter</li>
   170  				<li>Must contain at least 1 digit</li>
   171  			</ul>
   172  		</div>
   173  
   174  		<div style="grid-row: 14; align-self: center;">
   175  			Fields marked with <span class="mandatory">*</span> are mandatory.
   176  		</div>
   177  		<div style="grid-row: 14; grid-column: 2; text-align: right;">
   178  			<button type="reset">Reset</button>
   179  			<button type="submit" style="font-weight: bold;">Register</button>
   180  		</div>
   181  	</form>	
   182  </div>
   183  <div>
   184  	<p>Already have an account? Login <a href="{{getServerAddress}}/account/?path=login">here</a>.</p>
   185  </div>
   186  `