Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memo: code refactoring #324

Closed
37 of 43 tasks
virtualtam opened this issue Aug 19, 2015 · 3 comments
Closed
37 of 43 tasks

Memo: code refactoring #324

virtualtam opened this issue Aug 19, 2015 · 3 comments
Assignees
Labels
cleanup code cleanup and refactoring discussion enhancement

Comments

@virtualtam
Copy link
Member

virtualtam commented Aug 19, 2015

Motivation

Refactoring serves multiple purposes:

  • remove the logic from index.php
  • spread the logic over meaningful blocks: classes, functions
  • ease contribution
    • improve readability
    • improve stability / reduce the risk of regressions

See also: #71, #95, #130

Tasks

Remove dead code

Date formatting

#270 / #486 - Use DateTime to format dates and timestamps

  • linkdate2timestamp
  • linkdate2rfc822
  • linkdate2iso8601

Feed

#273, #515 - use templates for Atom & RSS feeds

  • showATOM
  • showRSS
  • showDailyRSS

HTML generation

#397 #560 - move PageBuilder to a proper file

  • buildLinkList
  • pageBuilder (class)
  • renderPage (the one chunk)
  • showDaily

HTTP

#332 - Detect https protocol by reverse-proxy rfc7239 : X-Forwarded-Proto
#333 - Refactor HTTP / Url functions => #334, #346

  • serverUrl
  • indexUrl
  • pageUrl
  • http_parse_headers_shaarli
  • getHTTP

Images

#345 - Refactor thumbnail functions
#687 - Use web-thumbnailer to retrieve thumbnails

  • computeThumbnail
  • genThumbnail
  • lazyThumbnail
  • resizeImage
  • thumbnail

Import & export

#493, #607 - Netscape import
#538 - Netscape export

  • importFile
  • hardcoded Netscape export generation

Links

  • html_extract_title

Shaarli utilities

#372 - Introduce a Shaarli class to group install/compatibility/update checks
#40 - Require write permissions only for relevant directories
#396 - application: refactor the install form generation

  • checkUpdate
  • checkPHPVersion
  • install
  • file permissions & ownership

Session & login management

#1005 - Refactor session management utilities
#587 - Improve IP ban file format
#1008 - Refactor login / ban management

  • setup_login_state
  • allIPs
  • fillSessionInfo
  • check_auth
  • isLoggedIn
  • logout
  • ban_loginFailed
  • ban_loginOk
  • ban_canLogin
  • getToken
  • tokenOk

Utilities

#437 - Logging: move logm() from index.php to application/Utils.php
#800 - Fix a warning generated in return_bytes and refactor it
#1122 - Replace logm() with a PSR-3 logger

  • logm
  • return_bytes
  • getMaxFileSize

Contributing

If there's a topic you'd like to work on, please say so in the comments or have a chat on Gitter before starting to code ;-)

Topics related to active issues will get extra attention.

I'll keep this issue updated as cleanup is progressing.

@nicolasdanelon
Copy link

@virtualtam I change the class name Auth (the idea came from Laravel) to Authentication but I have some doubt about the unit tests.. can you (or anybody) help with that?

@virtualtam
Copy link
Member Author

virtualtam commented Nov 25, 2015

Sure :)

Here is a suggestion for grouping and renaming existing methods into new Authentication and Session classes, acknowledging:

  • Authentication handles user login operations
  • Session handles the management of PHP $_SESSION variables

Authentication:

  • allIPs => getClientIp
  • check_auth => checkCredentials
  • fillSessionInfo => setSessionVariables
  • logout
  • setup_login_state & isLoggedIn => isLoggedIn

#1008 - LoginManager:

  • ban_loginOk => login
  • ban_loginFailed => banIp
  • ban_canLogin => checkIpBans

#1005 - Session:

  • getToken => generateToken
  • tokenOk => checkToken
  • is_session_id_valid (from Utils.php) => checkId

Now regarding how to proceed (& split work into sub-tasks):

  • refactoring should start with session methods (easy, low risk of side-effects),
  • authentication comes next,
    • starting with IP/ban management,
    • then session vars,
    • then login, logout & credential checks,
  • whenever possible, usage of globals should be avoided:
    • globals will very likely mess up with tests (side-effects due to variable scope)
    • any external dependency should be injected as a parameter, which also enables testing without being affected by the environment

virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 22, 2017
Relates to shaarli#324

Added:
- `SessionManager` class to group session-related features
- unit tests

Changed:
- `getToken()` -> `SessionManager->generateToken()`
- `tokenOk()` -> `SessionManager->checkToken()`
- inject a `$token` parameter to `PageBuilder`'s constructor

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 22, 2017
Relates to shaarli#324

Changed:
- `is_session_id_valid()` -> `SessionManager::checkId()`
- update tests

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 31, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Oct 31, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 7, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 8, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Nov 27, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Dec 2, 2017
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Jan 3, 2018
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
virtualtam added a commit to virtualtam/Shaarli that referenced this issue Feb 5, 2018
Relates to shaarli#324

Added:
- Add the `LoginManager` class to manage logins and bans

Changed:
- Refactor IP ban management
- Simplify logic
- Avoid using globals, inject dependencies

Fixed:
- Use `ban_duration` instead of `ban_after` when setting a new ban

Signed-off-by: VirtualTam <[email protected]>
@virtualtam
Copy link
Member Author

Closing as stale / obsolete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup code cleanup and refactoring discussion enhancement
Projects
None yet
Development

No branches or pull requests

3 participants