Skip to content

Commit f978a88

Browse files
committed
Merge pull request #626 from panique/develop
Develop
2 parents 7df7612 + ec7f5c7 commit f978a88

30 files changed

+681
-302
lines changed

.scrutinizer.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file just tells the wonderful code quality analyzer Scrutinizer (https://scrutinizer-ci.com/g/panique/huge/)
2+
# that we are using external services (Travis) to generate code coverage stats
3+
# TODO is this correct ?
4+
tools:
5+
external_code_coverage: true

.travis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
3+
php:
4+
- 5.5
5+
- 5.6
6+
- hhvm
7+
8+
before_install:
9+
- sudo apt-get update > /dev/null
10+
11+
before_script:
12+
- sudo apt-get install apache2
13+
- sudo a2enmod rewrite
14+
# configure apache virtual hosts, create vhost via travis-ci-apache file template
15+
- sudo cp -f travis-ci-apache /etc/apache2/sites-available/default
16+
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/default
17+
- sudo service apache2 restart
18+
# composer
19+
- composer self-update
20+
- composer install --prefer-source --no-interaction --dev
21+
# go to tests folder
22+
- cd tests
23+
24+
# run unit tests, create result file
25+
script: phpunit --configuration phpunit.xml --coverage-text --coverage-clover=coverage.clover
26+
27+
# gets tools from Scrutinizer, uploads unit tests results to Scrutinizer (?)
28+
after_script:
29+
- wget https://scrutinizer-ci.com/ocular.phar
30+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
# CHANGE LOG
22

3+
For the newest (und unstable) version always check the develop branch.
4+
5+
## 3.1
6+
7+
Code Quality at Scrutinizer 9.7/10, at Code Climate 3.9/4
8+
9+
**February 2015**
10+
11+
- [panique] several code quality improvements (and line reductions :) ) all over the project
12+
- [PR](https://github.com/panique/huge/pull/620) [owenr88] view rending now possible with multiple view files
13+
- [panique] lots of code refactorings and simplifications all over the project
14+
- [PR](https://github.com/panique/huge/pull/615) [Dominic28] Avatar can now be deleted by the user
15+
- [panique] First Unit tests :)
16+
- [panique] several code quality improvements all over the project
17+
- [panique] avatarModel code improvements
18+
- [panique] renamed AccountType stuff to UserRole, minor changes
19+
320
## 3.0
421

22+
Code Quality at Scrutinizer 9.3/10, at Code Climate 3.9/4
23+
524
**February 2015**
625

7-
- [panique] AccountTypeModel reduced to one method (removed duplicate code)
26+
- [panique] removed duplicate code in AccountTypeModel
827
- [PR](https://github.com/panique/huge/pull/587) [upperwood] Facebook stuff completely removed from SQL
928
- [panique] tiny text changes
1029

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
# HUGE
44

5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/panique/huge/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/panique/huge/?branch=master)
6+
[![Code Climate](https://codeclimate.com/github/panique/huge/badges/gpa.svg)](https://codeclimate.com/github/panique/huge)
7+
[![Travis CI](https://travis-ci.org/panique/huge.svg?branch=master)](https://travis-ci.org/panique/huge)
8+
[![Dependency Status](https://www.versioneye.com/user/projects/54ca11fbde7924f81a000010/badge.svg?style=flat)](https://www.versioneye.com/user/projects/54ca11fbde7924f81a000010)
9+
510
Just a simple user authentication solution inside a super-simple framework skeleton that works out-of-the-box
611
(and comes with an auto-installer), using the future-proof official bcrypt password hashing/salting implementation of
712
PHP 5.5+, plus some nice features that will speed up the time from idea to first usable prototype application
@@ -16,11 +21,7 @@ applications that - surprisingly and intentionally - go back to the basics of pr
1621
static classes, extremely simple constructs, not-totally-DRY code etc. while keeping the code extremely readable
1722
([StackOverflow](http://www.dev-metal.com/architecture-stackoverflow/), Wikipedia, SoundCloud).
1823

19-
Buzzwords: [KISS](http://en.wikipedia.org/wiki/KISS_principle), [YASNI](http://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it).
20-
21-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/panique/huge/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/panique/huge/?branch=master)
22-
[![Code Climate](https://codeclimate.com/github/panique/huge/badges/gpa.svg)](https://codeclimate.com/github/panique/huge)
23-
[![Dependency Status](https://www.versioneye.com/user/projects/54ca11fbde7924f81a000010/badge.svg?style=flat)](https://www.versioneye.com/user/projects/54ca11fbde7924f81a000010)
24+
Buzzwords: [KISS](http://en.wikipedia.org/wiki/KISS_principle), [YASNI](http://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it).
2425

2526
#### Quick-Index
2627

@@ -256,6 +257,23 @@ Then check your server's IP / domain. Everything should work fine.
256257

257258
By default HUGE has a demo-user: username is `demo`, password is `12345678`. The user is already activated.
258259

260+
### What the hell are .travis.yml, .scrutinizer.yml etc. ?
261+
262+
There are several files in the root folder of the project that might be irritating:
263+
264+
- *.htaccess* (optionally) routes all traffic to /public/index.php! If you installed this project correctly, then this
265+
file is not necessary, but as lots of people have problems setting up the vhost correctly, .htaccess it still there
266+
to increase security, even on partly-broken-installations.
267+
- *.scrutinizer.yml* (can be deleted): Configs for the external code quality analyzer Scrutinizer, just used here on
268+
GitHub, you don't need this for your project.
269+
- *.travis.yml* (can be deleted): Same like above. Travis is an external service that creates installations of this
270+
repo after each code change to make sure everything runs fine. Also runs the unit tests. You don't need this inside
271+
your project.
272+
- *composer.json* (important): You should know what this does. ;) This file says what external dependencies are used.
273+
- *travis-ci-apache* (can be deleted): Config file for Travis, see above, so Travis knows how to setup the Apache.
274+
275+
*README* and *CHANGELOG* are self-explaining.
276+
259277
#### Documentation <a name="documentation"></a>
260278

261279
A real documentation is in the making. Until then, please have a look at the code and use your IDE's code completion
@@ -324,3 +342,12 @@ https://github.com/panique/huge/issues?state=open
324342
- [Notes on password & hashing salting in upcoming PHP versions (PHP 5.5.x & 5.6 etc.)](https://github.com/panique/huge/wiki/Notes-on-password-&-hashing-salting-in-upcoming-PHP-versions-%28PHP-5.5.x-&-5.6-etc.%29)
325343
- [Some basic "benchmarks" of all PHP hash/salt algorithms](https://github.com/panique/huge/wiki/Which-hashing-&-salting-algorithm-should-be-used-%3F)
326344
- [How to prevent PHP sessions being shared between different apache vhosts / different applications](http://www.dev-metal.com/prevent-php-sessions-shared-different-apache-vhosts-different-applications/)
345+
346+
### Side-facts
347+
348+
1. Weird! When I renamed php-login to HUGE (to get rid off the too generic project name and to make it fitting nicely
349+
to MINI, TINY and MINI2, my other projects) I had a research if the word "huge" is already used in the php world for
350+
sure. Nothing came up. Then, weeks later, I stumbled upon this: https://github.com/ffremont/HugeRest
351+
I nice little framework in PHP, but it has only 1 star on Github, so it's obviously not so widely used. Looks very
352+
professional, too. Hmm.... The guy behind published the entire readme etc. in pure french (!), so it's hard to use
353+
for non-french-speaking people. However, I'm not related to him in any way, this is pure coincidence.

application/config/texts.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
"FEEDBACK_USER_EMAIL_ALREADY_TAKEN" => "Sorry, that email is already in use. Please choose another one.",
2424
"FEEDBACK_USERNAME_CHANGE_SUCCESSFUL" => "Your username has been changed successfully.",
2525
"FEEDBACK_USERNAME_AND_PASSWORD_FIELD_EMPTY" => "Username and password fields were empty.",
26-
"FEEDBACK_USERNAME_DOES_NOT_FIT_PATTERN" => "Username does not fit the name scheme: only a-Z and numbers are allowed, 2 to 64 characters.",
26+
"FEEDBACK_USERNAME_DOES_NOT_FIT_PATTERN" => "Username does not fit the name pattern: only a-Z and numbers are allowed, 2 to 64 characters.",
2727
"FEEDBACK_EMAIL_DOES_NOT_FIT_PATTERN" => "Sorry, your chosen email does not fit into the email naming pattern.",
2828
"FEEDBACK_EMAIL_SAME_AS_OLD_ONE" => "Sorry, that email address is the same as your current one. Please choose another one.",
2929
"FEEDBACK_EMAIL_CHANGE_SUCCESSFUL" => "Your email address has been changed successfully.",
3030
"FEEDBACK_CAPTCHA_WRONG" => "The entered captcha security characters were wrong.",
3131
"FEEDBACK_PASSWORD_REPEAT_WRONG" => "Password and password repeat are not the same.",
3232
"FEEDBACK_PASSWORD_TOO_SHORT" => "Password has a minimum length of 6 characters.",
3333
"FEEDBACK_USERNAME_TOO_SHORT_OR_TOO_LONG" => "Username cannot be shorter than 2 or longer than 64 characters.",
34-
"FEEDBACK_EMAIL_TOO_LONG" => "Email cannot be longer than 64 characters.",
3534
"FEEDBACK_ACCOUNT_SUCCESSFULLY_CREATED" => "Your account has been created successfully and we have sent you an email. Please click the VERIFICATION LINK within that mail.",
3635
"FEEDBACK_VERIFICATION_MAIL_SENDING_FAILED" => "Sorry, we could not send you an verification mail. Your account has NOT been created.",
3736
"FEEDBACK_ACCOUNT_CREATION_FAILED" => "Sorry, your registration failed. Please go back and try again.",
@@ -45,6 +44,9 @@
4544
"FEEDBACK_AVATAR_UPLOAD_TOO_BIG" => "Avatar source file is too big. 5 Megabyte is the maximum.",
4645
"FEEDBACK_AVATAR_FOLDER_DOES_NOT_EXIST_OR_NOT_WRITABLE" => "Avatar folder does not exist or is not writable. Please change this via chmod 775 or 777.",
4746
"FEEDBACK_AVATAR_IMAGE_UPLOAD_FAILED" => "Something went wrong with the image upload.",
47+
"FEEDBACK_AVATAR_IMAGE_DELETE_SUCCESSFUL" => "You successfully deleted your avatar.",
48+
"FEEDBACK_AVATAR_IMAGE_DELETE_NO_FILE" => "You don't have a custom avatar.",
49+
"FEEDBACK_AVATAR_IMAGE_DELETE_FAILED" => "Something went wrong while deleting your avatar.",
4850
"FEEDBACK_PASSWORD_RESET_TOKEN_FAIL" => "Could not write token to database.",
4951
"FEEDBACK_PASSWORD_RESET_TOKEN_MISSING" => "No password reset token.",
5052
"FEEDBACK_PASSWORD_RESET_MAIL_SENDING_ERROR" => "Password reset mail could not be sent due to: ",
@@ -54,10 +56,7 @@
5456
"FEEDBACK_PASSWORD_RESET_LINK_VALID" => "Password reset validation link is valid. Please change the password now.",
5557
"FEEDBACK_PASSWORD_CHANGE_SUCCESSFUL" => "Password successfully changed.",
5658
"FEEDBACK_PASSWORD_CHANGE_FAILED" => "Sorry, your password changing failed.",
57-
"FEEDBACK_ACCOUNT_UPGRADE_SUCCESSFUL" => "Account upgrade was successful.",
58-
"FEEDBACK_ACCOUNT_UPGRADE_FAILED" => "Account upgrade failed.",
59-
"FEEDBACK_ACCOUNT_DOWNGRADE_SUCCESSFUL" => "Account downgrade was successful.",
60-
"FEEDBACK_ACCOUNT_DOWNGRADE_FAILED" => "Account downgrade failed.",
59+
"FEEDBACK_ACCOUNT_TYPE_CHANGE_SUCCESSFUL" => "Account type change successful",
6160
"FEEDBACK_ACCOUNT_TYPE_CHANGE_FAILED" => "Account type change failed",
6261
"FEEDBACK_NOTE_CREATION_FAILED" => "Note creation failed.",
6362
"FEEDBACK_NOTE_EDITING_FAILED" => "Note editing failed.",

application/controller/LoginController.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ public function editUserEmail_action()
135135
}
136136

137137
/**
138-
* Upload avatar
138+
* Edit avatar
139139
* Auth::checkAuthentication() makes sure that only logged in users can use this action and see this page
140140
*/
141-
public function uploadAvatar()
141+
public function editAvatar()
142142
{
143143
Auth::checkAuthentication();
144-
$this->View->render('login/uploadAvatar', array(
144+
$this->View->render('login/editAvatar', array(
145145
'avatar_file_path' => AvatarModel::getPublicUserAvatarFilePathByUserId(Session::get('user_id'))
146146
));
147147
}
@@ -155,38 +155,50 @@ public function uploadAvatar_action()
155155
{
156156
Auth::checkAuthentication();
157157
AvatarModel::createAvatar();
158-
Redirect::to('login/uploadAvatar');
158+
Redirect::to('login/editAvatar');
159+
}
160+
161+
/**
162+
* Delete the current user's avatar
163+
* Auth::checkAuthentication() makes sure that only logged in users can use this action and see this page
164+
*/
165+
public function deleteAvatar_action()
166+
{
167+
Auth::checkAuthentication();
168+
AvatarModel::deleteAvatar(Session::get("user_id"));
169+
Redirect::to('login/editAvatar');
159170
}
160171

161172
/**
162173
* Show the change-account-type page
163174
* Auth::checkAuthentication() makes sure that only logged in users can use this action and see this page
164175
*/
165-
public function changeAccountType()
176+
public function changeUserRole()
166177
{
167178
Auth::checkAuthentication();
168-
$this->View->render('login/changeAccountType');
179+
$this->View->render('login/changeUserRole');
169180
}
170181

171182
/**
172183
* Perform the account-type changing
173184
* Auth::checkAuthentication() makes sure that only logged in users can use this action
174185
* POST-request
175186
*/
176-
public function changeAccountType_action()
187+
public function changeUserRole_action()
177188
{
178189
Auth::checkAuthentication();
179190

180191
if (Request::post('user_account_upgrade')) {
181192
// "2" is quick & dirty account type 2, something like "premium user" maybe. you got the idea :)
182-
AccountTypeModel::changeAccountType(2);
193+
UserRoleModel::changeUserRole(2);
183194
}
195+
184196
if (Request::post('user_account_downgrade')) {
185197
// "1" is quick & dirty account type 1, something like "basic user" maybe.
186-
AccountTypeModel::changeAccountType(1);
198+
UserRoleModel::changeUserRole(1);
187199
}
188200

189-
Redirect::to('login/changeAccountType');
201+
Redirect::to('login/changeUserRole');
190202
}
191203

192204
/**

application/core/Application.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,8 @@ public function __construct()
2626
// create array with URL parts in $url
2727
$this->splitUrl();
2828

29-
// check for controller: no controller given ? then make controller = default controller (from config)
30-
if (!$this->controller_name) {
31-
$this->controller_name = Config::get('DEFAULT_CONTROLLER');
32-
}
33-
34-
// check for action: no action given ? then make action = default action (from config)
35-
if (!$this->action_name OR (strlen($this->action_name) == 0)) {
36-
$this->action_name = Config::get('DEFAULT_ACTION');
37-
}
38-
39-
// rename controller name to real controller class/file name ("index" to "IndexController")
40-
$this->controller_name = ucwords($this->controller_name) . 'Controller';
29+
// creates controller and action names (from URL input)
30+
$this->createControllerAndActionNames();
4131

4232
// does such a controller exist ?
4333
if (file_exists(Config::get('PATH_CONTROLLER') . $this->controller_name . '.php')) {
@@ -87,4 +77,24 @@ private function splitUrl()
8777
$this->parameters = array_values($url);
8878
}
8979
}
80+
81+
/**
82+
* Checks if controller and action names are given. If not, default values are put into the properties.
83+
* Also renames controller to usable name.
84+
*/
85+
private function createControllerAndActionNames()
86+
{
87+
// check for controller: no controller given ? then make controller = default controller (from config)
88+
if (!$this->controller_name) {
89+
$this->controller_name = Config::get('DEFAULT_CONTROLLER');
90+
}
91+
92+
// check for action: no action given ? then make action = default action (from config)
93+
if (!$this->action_name OR (strlen($this->action_name) == 0)) {
94+
$this->action_name = Config::get('DEFAULT_ACTION');
95+
}
96+
97+
// rename controller name to real controller class/file name ("index" to "IndexController")
98+
$this->controller_name = ucwords($this->controller_name) . 'Controller';
99+
}
90100
}

application/core/Config.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
class Config
44
{
5-
private static $config;
5+
// this is public to allow better Unit Testing
6+
public static $config;
67

78
public static function get($key)
89
{
910
if (!self::$config) {
10-
self::$config = require('../application/config/config.' . Environment::get() . '.php');
11+
12+
$config_file = '../application/config/config.' . Environment::get() . '.php';
13+
14+
if (!file_exists($config_file)) {
15+
return false;
16+
}
17+
18+
self::$config = require $config_file;
1119
}
1220

1321
return self::$config[$key];
1422
}
15-
1623
}

application/core/Mail.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ public function sendMailWithPHPMailer($user_email, $from_email, $from_name, $sub
6767
$mail->Username = Config::get('EMAIL_SMTP_USERNAME');
6868
$mail->Password = Config::get('EMAIL_SMTP_PASSWORD');
6969
$mail->Port = Config::get('EMAIL_SMTP_PORT');
70-
}
71-
72-
// if you want to send mail via PHPMailer using native mail()
73-
if (!Config::get('EMAIL_USE_SMTP')) {
70+
} else {
7471
$mail->IsMail();
7572
}
7673

@@ -81,15 +78,16 @@ public function sendMailWithPHPMailer($user_email, $from_email, $from_name, $sub
8178
$mail->Subject = $subject;
8279
$mail->Body = $body;
8380

84-
// send mail
81+
// try to send mail
8582
$mail->Send();
83+
8684
if ($mail) {
8785
return true;
86+
} else {
87+
// if not successful, copy errors into Mail's error property
88+
$this->error = $mail->ErrorInfo;
89+
return false;
8890
}
89-
90-
// if not successful, copy errors into Mail's error property
91-
$this->error = $mail->ErrorInfo;
92-
return false;
9391
}
9492

9593
public function sendMail($user_email, $from_email, $from_name, $subject, $body)

application/core/Text.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ class Text
66

77
public static function get($key)
88
{
9+
// if not $key
10+
if (!$key) {
11+
return null;
12+
}
13+
14+
// load config file (this is only done once per application lifecycle)
915
if (!self::$texts) {
1016
self::$texts = require('../application/config/texts.php');
1117
}
1218

19+
// check if array key exists
20+
if (!array_key_exists($key, self::$texts)) {
21+
return null;
22+
}
23+
1324
return self::$texts[$key];
1425
}
1526

0 commit comments

Comments
 (0)