github.com/cs3org/reva/v2@v2.27.7/pkg/siteacc/account/edit/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 edit
    20  
    21  const tplJavaScript = `
    22  function verifyForm(formData) {
    23  	if (formData.getTrimmed("fname") == "") {
    24  		setState(STATE_ERROR, "Please specify your first name.", "form", "fname", true);
    25  		return false;
    26  	}
    27  
    28  	if (formData.getTrimmed("lname") == "") {
    29  		setState(STATE_ERROR, "Please specify your last name.", "form", "lname", true);	
    30  		return false;
    31  	}
    32  
    33  	if (formData.getTrimmed("role") == "") {
    34  		setState(STATE_ERROR, "Please specify your role within your site.", "form", "role", true);
    35  		return false;
    36  	}
    37  
    38  	if (formData.get("password") != "") {
    39  		if (formData.get("password2") == "") {
    40  			setState(STATE_ERROR, "Please confirm your new password.", "form", "password2", true);
    41  			return false;
    42  		}
    43  	
    44  		if (formData.get("password") != formData.get("password2")) {
    45  			setState(STATE_ERROR, "The entered passwords do not match.", "form", "password2", true);
    46  			return false;
    47  		}
    48  	}
    49  
    50  	return true;
    51  }
    52  
    53  function handleAction(action) {
    54  	const formData = new FormData(document.querySelector("form"));
    55  	if (!verifyForm(formData)) {
    56  		return;
    57  	}
    58  
    59  	setState(STATE_STATUS, "Updating account... this should only take a moment.", "form", null, false);
    60  
    61  	var xhr = new XMLHttpRequest();
    62      xhr.open("POST", "{{getServerAddress}}/" + action);
    63      xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
    64  
    65  	xhr.onload = function() {
    66  		if (this.status == 200) {
    67  			setState(STATE_SUCCESS, "Your account was successfully updated!", "form", null, true);
    68  		} else {
    69  			var resp = JSON.parse(this.responseText);
    70  			setState(STATE_ERROR, "An error occurred while trying to update your account:<br><em>" + resp.error + "</em>", "form", null, true);
    71  		}
    72  	}
    73  
    74  	var postData = {
    75  		"title": formData.getTrimmed("title"),
    76  		"firstName": formData.getTrimmed("fname"),
    77  		"lastName": formData.getTrimmed("lname"),
    78  		"role": formData.getTrimmed("role"),
    79  		"phoneNumber": formData.getTrimmed("phone"),
    80  		"password": {
    81  			"value": formData.get("password")
    82  		}
    83      };
    84  
    85      xhr.send(JSON.stringify(postData));
    86  }
    87  `
    88  
    89  const tplStyleSheet = `
    90  html * {
    91  	font-family: arial !important;
    92  }
    93  
    94  .mandatory {
    95  	color: red;
    96  	font-weight: bold;
    97  }
    98  `
    99  
   100  const tplBody = `
   101  <div>
   102  	<p>Edit your ScienceMesh Site Administrator Account information below.</p>
   103  	<p>Please note that you cannot modify your email address using this form.</p>
   104  </div>
   105  <div>&nbsp;</div>
   106  <div>
   107  	<form id="form" method="POST" class="box container-inline" style="width: 100%;"  onSubmit="handleAction('update?invoker=user'); return false;">
   108  		<div style="grid-row: 1;"><label for="title">Title: <span class="mandatory">*</span></label></div>
   109  		<div style="grid-row: 2;">
   110  			<select id="title" name="title">
   111  			{{$title := .Account.Title}}
   112  			{{range .Titles}}
   113  			<option value="{{.}}" {{if eq . $title}}selected{{end}}>{{.}}.</option>
   114  			{{end}}
   115  			</select>
   116  		</div>
   117  
   118  		<div style="grid-row: 3;"><label for="fname">First name: <span class="mandatory">*</span></label></div>
   119  		<div style="grid-row: 4;"><input type="text" id="fname" name="fname" value="{{.Account.FirstName}}"/></div>
   120  		<div style="grid-row: 3;"><label for="lname">Last name: <span class="mandatory">*</span></label></div>
   121  		<div style="grid-row: 4;"><input type="text" id="lname" name="lname" value="{{.Account.LastName}}"/></div>
   122  
   123  		<div style="grid-row: 5;"><label for="role">Role: <span class="mandatory">*</span></label></div>
   124  		<div style="grid-row: 6;"><input type="text" id="role" name="role" placeholder="Site administrator" value="{{.Account.Role}}"/></div>
   125  		<div style="grid-row: 5;"><label for="phone">Phone number:</label></div>
   126  		<div style="grid-row: 6;"><input type="text" id="phone" name="phone" placeholder="+49 030 123456" value="{{.Account.PhoneNumber}}"/></div>
   127  
   128  		<div style="grid-row: 7;">&nbsp;</div>
   129  
   130  		<div style="grid-row: 8; grid-column: 1 / span 2;">If you want to change your password, fill out the fields below. Otherwise, leave them empty to keep your current one.</div>
   131  		<div style="grid-row: 9;"><label for="password">New password:</label></div>
   132  		<div style="grid-row: 10;"><input type="password" id="password" name="password" autocomplete="new-password"/></div>
   133  		<div style="grid-row: 9"><label for="password2">Confirm new password:</label></div>
   134  		<div style="grid-row: 10;"><input type="password" id="password2" name="password2" autocomplete="new-password"/></div>
   135  
   136  		<div style="grid-row: 11; font-style: italic; font-size: 0.8em;">
   137  			The password must fulfil the following criteria:
   138  			<ul style="margin-top: 0em;">
   139  				<li>Must be at least 8 characters long</li>
   140  				<li>Must contain at least 1 lowercase letter</li>
   141  				<li>Must contain at least 1 uppercase letter</li>
   142  				<li>Must contain at least 1 digit</li>
   143  			</ul>
   144  		</div>
   145  
   146  		<div style="grid-row: 12; align-self: center;">
   147  			Fields marked with <span class="mandatory">*</span> are mandatory.
   148  		</div>
   149  		<div style="grid-row: 12; grid-column: 2; text-align: right;">
   150  			<button type="reset">Reset</button>
   151  			<button type="submit" style="font-weight: bold;">Save</button>
   152  		</div>
   153  	</form>
   154  </div>
   155  <div>
   156  	<p>Go <a href="{{getServerAddress}}/account/?path=manage">back</a> to the main account page.</p>
   157  </div>
   158  `