Browse Source

Start rewrite of user edit

leosw 8 months ago
parent
commit
604e42d323

+ 8 - 8
controllers/d.users.php

@@ -39,7 +39,7 @@ if(isset($controller->splitted_url[1])) {
 					// PROCESS DATA FROM FORM
 					$user = new User();
 					$user->name = $_POST['login'];
-					$user->email = strtolower($_POST['mail']);
+					$user->email = strtolower($_POST['email']);
 					$user->rank = "registered";
 
 					if($_POST['captcha'] == -2) {
@@ -54,7 +54,7 @@ if(isset($controller->splitted_url[1])) {
 								}
 							}
 							else {
-								header('Location: '.$config['rel_root_folder'].'user/signin?error=mail');
+								header('Location: '.$config['rel_root_folder'].'user/signin?error=email');
 							}
 						}
 						else {
@@ -76,7 +76,7 @@ if(isset($controller->splitted_url[1])) {
 				if (isset($_POST['submit'])) {
 					// PROCESS DATA FROM FORM
 					$user = new User();
-					$user->email = strtolower($_POST['mail']);
+					$user->email = strtolower($_POST['email']);
 
 					if($user->availableMail()) {
 						header('Location: '.$config['rel_root_folder'].'user/password_lost?error=1');
@@ -116,11 +116,11 @@ if(isset($controller->splitted_url[1])) {
 							$userProfile->name = $receivedUser->name;
 						else if($receivedUser->name != $userProfile->name)
 							$nameError=1;
-						$receivedUser->mail = strtolower($_POST['mail']);
-						if($receivedUser->mail != $userProfile->mail && $receivedUser->availableMail())
-							$userProfile->mail = $receivedUser->mail;
-						else if ($receivedUser->mail != $userProfile->mail)
-							$mailError=1;
+						$receivedUser->email = strtolower($_POST['email']);
+						if($receivedUser->email != $userProfile->email && $receivedUser->availableMail())
+							$userProfile->email = $receivedUser->email;
+						else if ($receivedUser->email != $userProfile->email)
+							$emailError=1;
 						if($_POST['password']!='')
 							$userProfile->password=sha1($_POST['password']);
 						$userProfile->locale=$_POST['locale'];

+ 7 - 7
models/d.users.php

@@ -11,12 +11,12 @@
 require_once($config['models_folder']."d.locales.php");
 
 $ranks = array(
-	"administrator"	=> array(1000,"Administrateur", "red"),
-	"moderator" 	=> array(800,"Modérateur", "orangered"),
-	"premium" 		=> array(600,"Membre premium", "orange"),
-	"registered"	=> array(400,"Utilisateur", "green"),
-	"blocked"		=> array(200,"Membre archivé", "#aaa"),
-	"visitor"		=> array(0,"Visiteur", "black")
+	"administrator"	=> array(1000,"Administrateur", "red", "administrator"),
+	"moderator" 	=> array(800,"Modérateur", "orangered", "moderator"),
+	"premium" 		=> array(600,"Membre premium", "orange", "premium"),
+	"registered"	=> array(400,"Utilisateur", "green", "registered"),
+	"blocked"		=> array(200,"Membre archivé", "#aaa", "blocked"),
+	"visitor"		=> array(0,"Visiteur", "black", "visitor")
 );
 
 class User
@@ -117,7 +117,7 @@ class User
 		global $ranks;
 
 		if( $no_html )
-			return $ranks[$this->rank][1];
+			return $this->rank;
 		else
 			return '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</span>';
 	}

+ 3 - 3
views/blocks/d.nav.html

@@ -11,9 +11,9 @@
 						<li class="on-bar"><a class="on-bar" href="<?=$config['rel_root_folder']?>community">Contribuer</a></li>
 						<li class="on-bar has-sub">
 							<? if ($user->get_id() == 0) { ?>
-							<a class="on-bar" href="#"><i class="icon fa fa-user"></i></a>
+							<a class="on-bar" href="#"><i class="icon fas fa-user"></i></a>
 							<? } elseif ($user->get_avatar() == NULL) { ?>
-							<a class="on-bar" href="#"><i class="icon fa fa-user-secret"></i></a>
+							<a class="on-bar" href="#"><i class="icon fas fa-user-secret"></i></a>
 							<? } else { ?>
 							<a class="on-bar" href="#"><img alt="Avatar" class="icon avatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$user->get_avatar()?>_s.jpg"></a>
 							<? } ?>
@@ -37,7 +37,7 @@
 								<? } ?>
 							</ul>
 						</li>
-						<li class="on-bar has-sub"><a class="on-bar" href="#"><i class="icon fa fa-question"></i></a>
+						<li class="on-bar has-sub"><a class="on-bar" href="#"><i class="icon fas fa-question"></i></a>
 							<ul>
 								<li><a href="<?=$config['rel_root_folder']?>wiki/help">Aide</a></li>
 								<li><a href="<?=$config['rel_root_folder']?>blog">Blog</a></li>

+ 1 - 1
views/d.user.password_lost.html

@@ -13,7 +13,7 @@
 				<? if(isset($_GET['error']) AND $_GET['error']==1) { ?>
 					<p style="color: red;">Cette adresse mail n'existe pas.</p>
 				<? } ?>
-				<input type="text" name="mail" id="mail" placeholder="Adresse mail">
+				<input type="text" name="email" id="email" placeholder="Adresse mail">
 				<input type="submit" name="submit" value="Envoyer un nouveau mot de passe">
 			</form>
 		</section>

+ 33 - 33
views/d.user.profile.edit.html

@@ -8,59 +8,59 @@
 		<? include('blocks/d.nav.html'); ?>
 
 		<section id="profile">
-			<? if ($userProfile->id != 0) { ?>
+			<? if ($userProfile->get_id() != 0) { ?>
 				<h1><?=$userProfile->name?></h1>
 				<article>
 					<? if(isset($nameError) AND $nameError==1) { ?>
 						<p style="color: #660000;">Veuillez choisir un autre nom d'utilisateur.</p>
 					<? } ?>
-					<? if(isset($nameError) AND $nameError==1) { ?>
-						<p style="color: #660000;">Veuillez choisir un autre nom d'utilisateur.</p>
+					<? if(isset($emailError) AND $emailError==1) { ?>
+						<p style="color: #660000;">Veuillez choisir un autre email.</p>
 					<? } ?>
 					<? if(isset($updated) AND $updated==1) { ?>
 						<p style="color: #006600;">Le profil a été mis à jour.</p>
 					<? } ?>
-					<form action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->id?>/edit" method="post" class="edituser" enctype="multipart/form-data">
-						<aside class="<?=$userProfile->avatar=='t'?'':'no'?>avatar">
+					<form action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->get_id()?>/edit" method="post" class="edituser" enctype="multipart/form-data">
+						<aside class="<?=$userProfile->get_avatar()!=NULL?'':'no'?>avatar">
 							<div id="picturebuttonscontainer">
 								<div id="picturebuttons">
-									<a href="#" id="uploadavatar"><i class="fa fa-camera"></i></a><a <?=$userProfile->avatar=='t'?'':'style="display: none;"'?> href="#" id="deleteavatar" style="font-size: 1.1em;"><i class="fa 	fa-trash"></i></a>
+									<a href="#" id="uploadavatar"><i class="fas fa-camera"></i></a><a <?=$userProfile->get_avatar()!=NULL?'':'style="display: none;"'?> href="#" id="deleteavatar" style="font-size: 1.1em;"><i class="fas fa-trash"></i></a>
 								</div>
 							</div>
 
-							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->id?>_p.jpg" alt="Profile picture">
-							<i id="profilenoavatar" class="fa fa-user-secret"></i>
+							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->get_id()?>_p.jpg" alt="Profile picture">
+							<i id="profilenoavatar" class="fas fa-user-secret"></i>
 						</aside>
 
-						<input id="avatarcheckbox" style="display: none;" type="checkbox" name="avatar" <?=$userProfile->avatar=='t'?'checked':''?>>
+						<input id="avatarcheckbox" style="display: none;" type="checkbox" name="avatar" <?=$userProfile->get_avatar()!=NULL?'checked':''?>>
 						<input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
 						<input id="avatarfile" name="avatarfile" style="display: none;" type="file" accept="image/*" />
 
-							<div id="description">
-								<ul>
-									<li><label for="name">Nom d'utilisateur :</label><input name="name" id="name" type="text" value="<?=$userProfile->name?>" placeholder="Charlie"></li>
-									<li><label for="mail">Adresse mail :</label><input name="mail" id="mail" type="text" value="<?=$userProfile->mail?>" placeholder="charlie@mountain.org"></li>
-									<li><label for="password">Mot de passe :</label><input name="password" id="password" type="password" placeholder="Nouveau mot de passe"></li>
-									<li><label for="locale">Langue :</label>
-										<select name="locale" id="locale">
-											<? foreach($config['locales'] as $locale) { ?>
-												<option <?=$userProfile->locale==$locale[0]?'selected':''?> value="<?=$locale[0]?>"><?=$locale[5]?></option>
-											<? } ?>
-										</select></li>
-									<? if($user->role >= 1000) { ?>
-									<li><label for="role">Rang : </label>
-										<select name="role" id="role">
-											<? foreach($config['roles'] as $role) { ?>
-												<option <?=$userProfile->role==$role[0]?'selected':''?> value="<?=$role[0]?>"><?=$role[1]?></option>
-											<? } ?>
-										</select></li>
-									<? } ?>
-									<li><label for="website">Site internet :</label><input name="website" id="website" type="text" value="<?=$userProfile->website?>" placeholder="mountain.org"></li>
+						<div id="description">
+							<ul>
+								<li><label for="name">Nom d'utilisateur :</label><input name="name" id="name" type="text" value="<?=$userProfile->name?>" placeholder="Charlie"></li>
+								<li><label for="email">Adresse mail :</label><input name="email" id="email" type="text" value="<?=$userProfile->email?>" placeholder="charlie@mountain.org"></li>
+								<li><label for="password">Mot de passe :</label><input name="password" id="password" type="password" placeholder="Nouveau mot de passe"></li>
+								<li><label for="locale">Langue :</label>
+									<select name="locale" id="locale">
+										<? foreach($config['locales'] as $locale) { ?>
+											<option <?=$userProfile->locale==$locale[0]?'selected':''?> value="<?=$locale[0]?>"><?=$locale[5]?></option>
+										<? } ?>
+									</select></li>
+								<? if($user->rankIsHigher("administrator")) { ?>
+								<li><label for="rank">Rang : </label>
+									<select name="rank" id="rank">
+										<? foreach($ranks as $rank) { ?>
+											<option <?=$userProfile->get_rank(true)==$rank[3]?'selected':''?> value="<?=$rank[0]?>"><?=$rank[1]?></option>
+										<? } ?>
+									</select></li>
+								<? } ?>
+								<li><label for="website">Site internet :</label><input name="website" id="website" type="text" value="<?=$userProfile->website?>" placeholder="mountain.org"></li>
 
-									<input name="submit" id="submit" type="submit" value="Envoyer">
-								</ul>
-							</div>
-							<div style="clear:both;"></div>
+								<input name="submit" id="submit" type="submit" value="Envoyer">
+							</ul>
+						</div>
+						<div style="clear:both;"></div>
 					</form>
 				</article>
 			<? } else { ?>

+ 2 - 2
views/d.user.signin.html

@@ -13,7 +13,7 @@
 				<? if(isset($_GET['error']) AND $_GET['error']=="name") { ?>
 					<p style="color: red;">Veuillez choisir un autre nom d'utilisateur.</p>
 				<? } ?>
-				<? if(isset($_GET['error']) AND $_GET['error']=="mail") { ?>
+				<? if(isset($_GET['error']) AND $_GET['error']=="email") { ?>
 					<p style="color: red;">Cette adresse mail est déjà prise.</p>
 				<? } ?>
 				<? if(isset($_GET['error']) AND $_GET['error']=="empty") { ?>
@@ -25,7 +25,7 @@
 				<? } ?>
 				<input type="text" name="login" id="login" placeholder="Nom d'utilisateur">
 				<input type="password" name="password" id="password" placeholder="Mot de passe">
-				<input type="text" name="mail" id="mail" placeholder="Adresse mail">
+				<input type="text" name="email" id="email" placeholder="Adresse mail">
 				<p id="captcha">
 					<input type="hidden" id="captchahidden" name="captcha" value="10">
 					<span id="captchatext">Merci d'attendre <b id="captchasec">10 s</b> avant de pouvoir vous inscrire.<br>