Skip to content

Commit

Permalink
v 0.7.0
Browse files Browse the repository at this point in the history
- Add github actions.
- Update dependencies.
- New module : change email.
- Fix behavior when empty avatar.
  • Loading branch information
Darklg committed Aug 8, 2024
1 parent 98906ac commit 54d66cd
Show file tree
Hide file tree
Showing 22 changed files with 248 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
19 changes: 19 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: PHP Lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
phplint:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: PHP Lint
uses: michaelw90/PHP-Lint@2.1.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mo.php
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 WPUtilities
Copyright (c) 2024 WPUtilities

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# WPU Extranet

[![PHP workflow](https://github.com/WordPressUtilities/wpu_extranet/actions/workflows/php.yml/badge.svg 'PHP workflow')](https://github.com/WordPressUtilities/wpu_extranet/actions)

Simple toolbox to create an extranet or a customer account.

## Todo
Expand Down
1 change: 1 addition & 0 deletions inc/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
142 changes: 142 additions & 0 deletions inc/modules/change-email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Email
---------------------------------------------------------- */

/* Form action
-------------------------- */

function wpu_extranet_change_email__action() {
if (empty($_POST)) {
return '';
}
if (!is_user_logged_in()) {
return '';
}
if (!isset($_POST['current_email'], $_POST['new_email'], $_POST['confirm_new_email'])) {
return '';
}

if (!isset($_POST['wpuextranet_changeemail']) || !wp_verify_nonce($_POST['wpuextranet_changeemail'], 'wpuextranet_changeemail_action')) {
return '';
}

$current_email = trim($_POST['current_email']);
$new_email = trim($_POST['new_email']);
$confirm_new_email = trim($_POST['confirm_new_email']);

$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
if (!$current_user) {
return;
}

/* Check errors */
$errors = array();

/* Empty fields */
if (empty($current_email) || empty($new_email) || empty($confirm_new_email)) {
$errors[] = __('All fields are required.', 'wpu_extranet');
}

/* Invalid email */
if (!is_email($current_email) || !is_email($new_email) || !is_email($confirm_new_email)) {
$errors[] = __('Invalid email.', 'wpu_extranet');
}

/* Invalid current email */
if($current_email == $new_email){
$errors[] = __('New email is the same as the current email.', 'wpu_extranet');
}

/* New emails do not match */
if ($new_email != $confirm_new_email) {
$errors[] = __('Emails do not match.', 'wpu_extranet');
}

/* E-mail is already in use */
if (email_exists($new_email)) {
$errors[] = __('Email is already in use.', 'wpu_extranet');
}

$errors = apply_filters('wpu_extranet_change_email__action_errors', $errors, $current_email, $new_email, $confirm_new_email);

$html_return = '';
if (empty($errors)) {
// Change email
wp_update_user(array(
'ID' => $user_id,
'user_email' => $new_email
));
$html_return = '<p class="extranet-message extranet-message--success form-email-success">' . __('Email successfully updated!', 'wpu_extranet') . '</p>';
} else {
$html_return = '<p class="extranet-message extranet-message--error form-email-error">' . implode('<br />', $errors) . '</p>';
}

return $html_return;
}

/* HTML Form
-------------------------- */


function wpu_extranet_change_email__form($args = array()) {
if (!is_array($args)) {
$args = array();
}
if (!isset($args['before_fields'])) {
$args['before_fields'] = '';
}
$html = '';

$userdata = get_userdata(get_current_user_id());

$settings = wpu_extranet_get_skin_settings();

$html .= '<div class="' . $settings['form_wrapper_classname'] . ' form-changeemail-wrapper">';
$html .= '<h3>' . __('Change email', 'wpu_extranet') . '</h3>';
$html .= '<form name="changeemailform" id="changeemailform" action="' . get_permalink() . '#changeemailform" method="post">';
$html .= $args['before_fields'];
$html .= '<ul class="' . $settings['form_items_classname'] . '">';
$html .= wpu_extranet__display_field('current_email', array(
'type' => 'email',
'attributes' => 'readonly minlength="6" autocomplete="off" required="required"',
'label' => __('Your current email', 'wpu_extranet'),
'value' => $userdata->user_email
));
$html .= wpu_extranet__display_field('new_email', array(
'type' => 'email',
'attributes' => 'minlength="6" autocomplete="off" required="required"',
'label' => __('New email', 'wpu_extranet')
));
$html .= wpu_extranet__display_field('confirm_new_email', array(
'type' => 'email',
'attributes' => 'minlength="6" autocomplete="off" required="required"',
'label' => __('Confirm new email', 'wpu_extranet')
));
$html .= '<li class="' . $settings['form_box_submit_classname'] . '">';
$html .= wp_nonce_field('wpuextranet_changeemail_action', 'wpuextranet_changeemail', true, false);
$html .= '<button class="' . $settings['form_submit_button_classname'] . '" type="submit"><span>' . __('Change email', 'wpu_extranet') . '</span></button>';
$html .= '</li>';
$html .= '</ul>';
$html .= '</form>';
$html .= '</div>';

return $html;
}

/* ----------------------------------------------------------
Example code
---------------------------------------------------------- */

/*
$html_return_email = wpu_extranet_change_email__action();
get_header();
echo '<h1>' . get_the_title() . '</h1>';
echo wpu_extranet_change_email__form(array(
'before_fields' => $html_return_email
));
get_footer();
*/
1 change: 1 addition & 0 deletions inc/modules/change-password.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Password
Expand Down
5 changes: 5 additions & 0 deletions inc/modules/edit-metas.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Metas
Expand Down Expand Up @@ -64,6 +65,10 @@ function wpu_extranet_update_metas__action__avatar($user_id) {
return true;
}

if (!isset($_FILES["wpuextranet_avatar"]) || empty($_FILES["wpuextranet_avatar"]['tmp_name'])) {
return false;
}

/* Check attachment types */
$allowed_extensions = array("image/png", "image/jpg", "image/jpeg");
if (!in_array(mime_content_type($_FILES["wpuextranet_avatar"]['tmp_name']), $allowed_extensions)) {
Expand Down
1 change: 1 addition & 0 deletions inc/modules/lost-password.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Lost password
Expand Down
1 change: 1 addition & 0 deletions inc/modules/register.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Honeypot
Expand Down
1 change: 1 addition & 0 deletions inc/notifications.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Disable password change mail
Expand Down
1 change: 1 addition & 0 deletions inc/pages.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
Pages settings
Expand Down
1 change: 1 addition & 0 deletions inc/permissions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* Failed login in front : redirect to the home page
-------------------------- */
Expand Down
1 change: 1 addition & 0 deletions inc/user.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
defined('ABSPATH') || die;

/* ----------------------------------------------------------
User fields
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
1 change: 1 addition & 0 deletions lang/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
1 change: 1 addition & 0 deletions lang/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php /* Silence */
2 changes: 2 additions & 0 deletions lang/wpu_extranet-fr_FR.l10n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['All fields are required.'=>'Tous les champs sont requis.','Invalid email.'=>'E-mail invalide.','New email is the same as the current email.'=>'Le nouvel e-mail est le même que l’e-mail actuel.','Emails do not match.'=>'Les e-mails ne sont pas identiques.','Email is already in use.'=>'L’e-mail est déjà utilisé.','Email successfully updated!'=>'L’e-mail a été mis à jour avec succès !','Change email'=>'Changer d\'adresse e-mail','Your current email'=>'Votre adresse e-mail actuelle','New email'=>'Nouvel e-mail','Confirm new email'=>'Confirmez votre nouvel e-mail','Current password is incorrect.'=>'Le mot de passe actuel est incorrect.','Passwords do not match.'=>'Les mots de passe ne correspondent pas.','Password is too short, minimum of 6 characters.'=>'Le mot de passe est trop court, minimum de 6 caractères.','Password successfully changed!'=>'Mot de passe changé avec succès !','Error:'=>'Erreur :','Change password'=>'Changer le mot de passe','Enter your current password'=>'Veuillez saisir votre mot de passe actuel','New password'=>'Nouveau mot de passe','Confirm new password'=>'Confirmer le nouveau mot de passe','Profile successfully updated!'=>'Profil mis à jour avec succès!','Infos'=>'Infos','The current avatar is generated by %s.'=>'L’avatar actuel est généré par %s.','Delete this avatar'=>'Supprimer cet avatar','Avatar'=>'Avatar','Username'=>'Nom d\'utilisateur','Email'=>'E-mail','Edit my infos'=>'Modifier mes infos','Check your email for the confirmation link.'=>'Vérifiez vos courriels pour y trouver le lien de confirmation.','Your account could not be found.'=>'Votre compte est introuvable.','Reset password failed.'=>'Échec de la réinitialisation du mot de passe.','Username or Email Address'=>'Identifiant ou adresse email','Get New Password'=>'Obtenir un nouveau mot de passe','Registration confirmation will be emailed to you.'=>'La confirmation d’inscription vous sera envoyée par courriel.','This username already exists.'=>'Ce nom d’utilisateur existe déjà.','This email is already registered.'=>'Cet e-mail est déjà enregistré.','This username contains invalid characters.'=>'Ce nom d’utilisateur contient des caractères non valides.','Registration failed.'=>'Échec de l’inscription.','Password'=>'Mot de passe','Register'=>'S\'inscrire','Log out'=>'Se déconnecter','First name'=>'Prénom','Last name'=>'Nom'],'language'=>'fr_FR','x-generator'=>'Poedit 3.4.4'];
Binary file modified lang/wpu_extranet-fr_FR.mo
Binary file not shown.
56 changes: 46 additions & 10 deletions lang/wpu_extranet-fr_FR.po
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
msgid ""
msgstr ""
"Project-Id-Version: WPU Extranet\n"
"POT-Creation-Date: 2022-08-04 13:54+0200\n"
"POT-Creation-Date: 2024-08-08 12:06+0200\n"
"PO-Revision-Date: \n"
"Last-Translator: Darklg <darklg.blog@gmail.com>\n"
"Language-Team: \n"
"Language: fr_FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.1.1\n"
"X-Generator: Poedit 3.4.4\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-KeywordsList: __;_e\n"
"X-Poedit-SearchPath-0: ../.\n"

#: .././inc/modules/change-password.php:40
#: .././inc/modules/change-email.php:40 .././inc/modules/change-password.php:40
msgid "All fields are required."
msgstr "Tous les champs sont requis."

#: .././inc/modules/change-email.php:45
msgid "Invalid email."
msgstr "E-mail invalide."

#: .././inc/modules/change-email.php:50
msgid "New email is the same as the current email."
msgstr "Le nouvel e-mail est le même que l’e-mail actuel."

#: .././inc/modules/change-email.php:55
msgid "Emails do not match."
msgstr "Les e-mails ne sont pas identiques."

#: .././inc/modules/change-email.php:60
msgid "Email is already in use."
msgstr "L’e-mail est déjà utilisé."

#: .././inc/modules/change-email.php:72
msgid "Email successfully updated!"
msgstr "L’e-mail a été mis à jour avec succès !"

#: .././inc/modules/change-email.php:98 .././inc/modules/change-email.php:120
msgid "Change email"
msgstr "Changer d'adresse e-mail"

#: .././inc/modules/change-email.php:105
msgid "Your current email"
msgstr "Votre adresse e-mail actuelle"

#: .././inc/modules/change-email.php:111
msgid "New email"
msgstr "Nouvel e-mail"

#: .././inc/modules/change-email.php:116
msgid "Confirm new email"
msgstr "Confirmez votre nouvel e-mail"

#: .././inc/modules/change-password.php:45
msgid "Current password is incorrect."
msgstr "Le mot de passe actuel est incorrect."
Expand Down Expand Up @@ -61,32 +97,32 @@ msgstr "Confirmer le nouveau mot de passe"
msgid "Profile successfully updated!"
msgstr "Profil mis à jour avec succès!"

#: .././inc/modules/edit-metas.php:111
#: .././inc/modules/edit-metas.php:115
msgid "Infos"
msgstr "Infos"

#: .././inc/modules/edit-metas.php:118
#: .././inc/modules/edit-metas.php:138
#, php-format
msgid "The current avatar is generated by %s."
msgstr "L’avatar actuel est généré par %s."

#: .././inc/modules/edit-metas.php:121
#: .././inc/modules/edit-metas.php:141
msgid "Delete this avatar"
msgstr "Supprimer cet avatar"

#: .././inc/modules/edit-metas.php:124
#: .././inc/modules/edit-metas.php:144
msgid "Avatar"
msgstr "Avatar"

#: .././inc/modules/edit-metas.php:133 .././inc/modules/register.php:140
#: .././inc/modules/edit-metas.php:154 .././inc/modules/register.php:140
msgid "Username"
msgstr "Nom d'utilisateur"

#: .././inc/modules/edit-metas.php:138 .././inc/modules/register.php:146
#: .././inc/modules/edit-metas.php:159 .././inc/modules/register.php:146
msgid "Email"
msgstr "E-mail"

#: .././inc/modules/edit-metas.php:151
#: .././inc/modules/edit-metas.php:175
msgid "Edit my infos"
msgstr "Modifier mes infos"

Expand Down
Loading

0 comments on commit 54d66cd

Please sign in to comment.