Add email to create user, in setting edit user permission and emailmanager file
This commit is contained in:
		@@ -1,16 +1,18 @@
 | 
			
		||||
<?php
 | 
			
		||||
if (isset($_POST) && !empty($_POST)){
 | 
			
		||||
	$userManager = new UserManager();
 | 
			
		||||
	if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
 | 
			
		||||
		$oldPassword = $_POST['oldPassword'];
 | 
			
		||||
		$newPassword = $_POST['newPassword1'];
 | 
			
		||||
		$newPassword2 = $_POST['newPassword2'];
 | 
			
		||||
		UserManager::changePassword($oldPassword, $newPassword, $newPassword2);
 | 
			
		||||
		$userManager->changePassword($oldPassword, $newPassword, $newPassword2);
 | 
			
		||||
		header('Location: ' . BASEURL . 'logout');
 | 
			
		||||
		die();
 | 
			
		||||
	} else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") {
 | 
			
		||||
		$userName = $_POST['userName'];
 | 
			
		||||
		$password = $_POST['userPassword'];
 | 
			
		||||
		UserManager::createUser($userName, $password);
 | 
			
		||||
		$email = $_POST['userEmail'];
 | 
			
		||||
		$userManager->createUser($userName, $password, $email);
 | 
			
		||||
		header('Location: ' . BASEURL . 'setting');
 | 
			
		||||
		die();
 | 
			
		||||
	} else if (isset($_POST['submitEnableOta']) && $_POST['submitEnableOta'] != "") {
 | 
			
		||||
@@ -20,9 +22,13 @@ if (isset($_POST) && !empty($_POST)){
 | 
			
		||||
		$ga = new PHPGangsta_GoogleAuthenticator();
 | 
			
		||||
		$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2);    // 2 = 2*30sec clock tolerance
 | 
			
		||||
		 if ($checkResult) {
 | 
			
		||||
			 UserManager::setOta($otaCode, $otaSecret);
 | 
			
		||||
			 $userManager->setOta($otaCode, $otaSecret);
 | 
			
		||||
		 }
 | 
			
		||||
		header('Location: ' . BASEURL . 'setting');
 | 
			
		||||
		die();
 | 
			
		||||
	} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
 | 
			
		||||
		$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
 | 
			
		||||
		header('Location: ' . BASEURL . 'setting');
 | 
			
		||||
		die();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								app/models/managers/EmailManager.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/models/managers/EmailManager.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
<?php
 | 
			
		||||
class EmailManager {
 | 
			
		||||
	public function SendTo ($pro, $predmet, $zprava) {
 | 
			
		||||
			$email = "From: EnergyCounter@steelants.cz";
 | 
			
		||||
			$email .= "\nMIME-Version: 1.0\n";
 | 
			
		||||
			$email .= "Content-Type: text/html; charset=\"utf-8\"\n";
 | 
			
		||||
			if (!mb_send_mail ($pro, $predmet, $zprava, $email)) {
 | 
			
		||||
				throw new PDOException("!Email se nepodařilo odeslat!");
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
}
 | 
			
		||||
@@ -43,7 +43,7 @@ class UserManager
 | 
			
		||||
 | 
			
		||||
	public static function login ($username, $password, $rememberMe) {
 | 
			
		||||
		try {
 | 
			
		||||
			if ($user = Db::loadOne ('SELECT * FROM users WHERE LOWER(username)=LOWER(?)', array ($username))) {
 | 
			
		||||
			if ($user = Db::loadOne ('SELECT * FROM users WHERE LOWER(username)=LOWER(?) OR LOWER(email)=LOWER(?)', array ($username, $username))) {
 | 
			
		||||
				if ($user['password'] == UserManager::getHashPassword($password)) {
 | 
			
		||||
					if (isset($rememberMe) && $rememberMe == 'true') {
 | 
			
		||||
						setcookie ("rememberMe", self::setEncryptedCookie($user['username']), time () + (30 * 24 * 60 * 60 * 1000), BASEDIR, $_SERVER['HTTP_HOST'], 1);
 | 
			
		||||
@@ -69,7 +69,7 @@ class UserManager
 | 
			
		||||
 | 
			
		||||
	public static function loginNew ($username, $password) {
 | 
			
		||||
		try {
 | 
			
		||||
			if ($user = Db::loadOne ('SELECT * FROM users WHERE LOWER(username)=LOWER(?)', array ($username))) {
 | 
			
		||||
			if ($user = Db::loadOne ('SELECT * FROM users WHERE LOWER(username)=LOWER(?) OR LOWER(email)=LOWER(?)', array ($username, $username))) {
 | 
			
		||||
				if ($user['password'] == UserManager::getHashPassword($password)) {
 | 
			
		||||
					return $user['user_id'];
 | 
			
		||||
				} else {
 | 
			
		||||
@@ -152,6 +152,12 @@ class UserManager
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function setUserDataAdmin ($type, $value, $id) {
 | 
			
		||||
		if ($id) {
 | 
			
		||||
			Db::command ('UPDATE users SET ' . $type . '=? WHERE user_id=?', array ($value, $id));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function getHashPassword ($password) {
 | 
			
		||||
		$salt = "s0mRIdlKvI";
 | 
			
		||||
		$hashPassword = hash('sha512', ($password . $salt));
 | 
			
		||||
@@ -181,8 +187,9 @@ class UserManager
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function createUser($userName, $password){
 | 
			
		||||
		$userId = Db::loadOne('SELECT * FROM users WHERE username = ?;', array($userName))['user_id'];
 | 
			
		||||
	public static function createUser ($userName, $password, $email) {
 | 
			
		||||
		$email = strtolower ($email);
 | 
			
		||||
		$userId = Db::loadOne ('SELECT * FROM users WHERE LOWER (username) = LOWER (?) OR LOWER (email) = LOWER (?);', array ($userName, $email))['user_id'];
 | 
			
		||||
		if ($userId != null) {
 | 
			
		||||
			return false;
 | 
			
		||||
		};
 | 
			
		||||
@@ -190,6 +197,7 @@ class UserManager
 | 
			
		||||
			$user = [
 | 
			
		||||
				'username' => $userName,
 | 
			
		||||
				'password' => self::getHashPassword($password),
 | 
			
		||||
				'email' => $email,
 | 
			
		||||
			];
 | 
			
		||||
			return Db::add ('users', $user);
 | 
			
		||||
		} catch(PDOException $error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -117,6 +117,7 @@
 | 
			
		||||
							<th><?php $LANGMNG->echo('t_avatar');?></th>
 | 
			
		||||
							<th><?php $LANGMNG->echo('t_userName');?></th>
 | 
			
		||||
							<th><?php $LANGMNG->echo('t_ota');?></th>
 | 
			
		||||
							<th><?php $LANGMNG->echo('t_permission');?></th>
 | 
			
		||||
							<th><?php $LANGMNG->echo('t_action');?></th>
 | 
			
		||||
						</tr>
 | 
			
		||||
					</thead>
 | 
			
		||||
@@ -126,6 +127,15 @@
 | 
			
		||||
								<td><img src="<?php echo $user['gavatar_url']; ?>" /></td>
 | 
			
		||||
								<td><?php echo $user['username']; ?></td>
 | 
			
		||||
								<td><?php echo ($user['ota'] ? '<span class="fa"></span>' : ''); ?></td>
 | 
			
		||||
								<td>
 | 
			
		||||
									<form method="post" enctype="multipart/form-data">
 | 
			
		||||
										<input type="hidden" name="userID" value="<?php echo $user['user_id']; ?>"/>
 | 
			
		||||
										<select class="input" name="userPermission" onchange="this.form.submit();">
 | 
			
		||||
											<option value="0"<?php echo (empty ($user['permission']) ? " selected" : "") ?>><?php $LANGMNG->echo('t_permission_user'); ?></option>
 | 
			
		||||
											<option value="1"<?php echo (!empty ($user['permission']) ? " selected" : "") ?>><?php $LANGMNG->echo('t_permission_admin'); ?></option>
 | 
			
		||||
										</select>
 | 
			
		||||
									</form>
 | 
			
		||||
								</td>
 | 
			
		||||
								<td><button name="deleteUser" type="button" class="button is-danger fa"></button></td>
 | 
			
		||||
							</tr>
 | 
			
		||||
						<?php } ?>
 | 
			
		||||
@@ -143,6 +153,10 @@
 | 
			
		||||
						<div class="label"><?php $LANGMNG->echo('l_password') ?>:</div>
 | 
			
		||||
						<input type="password" class="input" name="userPassword" value="">
 | 
			
		||||
					</div>
 | 
			
		||||
					<div class="field">
 | 
			
		||||
						<div class="label"><?php $LANGMNG->echo('l_email') ?>:</div>
 | 
			
		||||
						<input type="email" class="input" name="userEmail" value="">
 | 
			
		||||
					</div>
 | 
			
		||||
					<div class="field">
 | 
			
		||||
						<input type="submit" name="submitCreateUser" class="button" value="Uložit">
 | 
			
		||||
					</div>
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,7 @@ return $lang = [
 | 
			
		||||
	'l_notificationStatus' => 'Notification status',
 | 
			
		||||
	'l_userName' => 'Uživatelské jméno',
 | 
			
		||||
	'l_password' => 'Heslo',
 | 
			
		||||
	'l_email' => 'Email',
 | 
			
		||||
	'l_oldPassword' => 'Staré Heslo',
 | 
			
		||||
	'l_newPassword' => 'Nové Heslo',
 | 
			
		||||
	'l_uploadFirmware' => 'Nahrát Firmware',
 | 
			
		||||
@@ -79,6 +80,9 @@ return $lang = [
 | 
			
		||||
	't_networkSetting' => 'Nastavení Sítě',
 | 
			
		||||
	't_deviceVersion' => 'Nastavení Verze',
 | 
			
		||||
	't_ota' => 'OTA',
 | 
			
		||||
	't_permission' => 'Oprávnění',
 | 
			
		||||
	't_permission_user' => 'Uživatel',
 | 
			
		||||
	't_permission_admin' => 'Administrátor',
 | 
			
		||||
	't_listUsers' => 'Seznam Uživatelů',
 | 
			
		||||
	't_avatar' => 'Avatar',
 | 
			
		||||
	't_listRooms' => 'Seznam Místností',
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,7 @@ return $lang = [
 | 
			
		||||
	'l_notificationStatus' => 'Notification status',
 | 
			
		||||
	'l_userName' => 'Username',
 | 
			
		||||
	'l_password' => 'Password',
 | 
			
		||||
	'l_email' => 'Email',
 | 
			
		||||
	'l_oldPassword' => 'Old Password',
 | 
			
		||||
	'l_newPassword' => 'New Password',
 | 
			
		||||
	'l_uploadFirmware' => 'Upload Firmware',
 | 
			
		||||
@@ -79,6 +80,9 @@ return $lang = [
 | 
			
		||||
	't_networkSetting' => 'Network Setting',
 | 
			
		||||
	't_deviceVersion' => 'Version Setting',
 | 
			
		||||
	't_ota' => 'OTA',
 | 
			
		||||
	't_permission' => 'Permission',
 | 
			
		||||
	't_permission_user' => 'User',
 | 
			
		||||
	't_permission_admin' => 'Admin',
 | 
			
		||||
	't_listUsers' => 'User List',
 | 
			
		||||
	't_avatar' => 'Avatar',
 | 
			
		||||
	't_listRooms' => 'Room List',
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,7 @@ return $lang = [
 | 
			
		||||
	'l_sleepTime' => 'Apparaat slaaptijd',
 | 
			
		||||
	'l_atHome' => 'Thuis',
 | 
			
		||||
	'l_nameAt' => 'Naam',
 | 
			
		||||
	'l_email' => 'Email',
 | 
			
		||||
	'l_lastSeen' => 'Laatst gezien',
 | 
			
		||||
	'l_notificationStatus' => 'Notificatie status',
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -56,6 +56,7 @@ return $lang = [
 | 
			
		||||
	'l_notificationStatus' => 'Stan powiadomienia',
 | 
			
		||||
	'l_userName' => 'Username', //newOne
 | 
			
		||||
	'l_password' => 'Password', //newOne
 | 
			
		||||
	'l_email' => 'Email',
 | 
			
		||||
	'l_oldPassword' => 'Old Password', //newOne
 | 
			
		||||
	'l_newPassword' => 'New Password', //newOne
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user