<<

NAME

ProductOpener::Users - manage user profiles and sessions

SYNOPSIS

ProductOpener::Users contains functions to create and edit user profiles and to manage user sessions.

    use ProductOpener::Users qw/:all/;

        [..]

        init_user($request_ref);

DESCRIPTION

[..]

FUNCTIONS

generate_token()

generate_token() generates a secure token for the session IDs. More information: https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html#Session_ID_Content_.28or_Value.29

Return values

Creates a new session ID

create_password_hash($password)

Takes $password and hashes it using scrypt

create_password_hash() This function hashes the user's password using Scrypt which is a salted hashing algorithm. Password salting adds a random sequence of data to each password and then hashes it. Password hashing is turning a password into a random string by using some algorithm.

Arguments

$password : String

Return values

Returns the salted hashed sequence.

check_password_hash ($password, $hash)

Turns $password into hash using md5 or scrypt and compares it to $hash.

check_password_hash() This function takes the hash generated by create_password_hash() and the input password string. Further, it hashes the input password string md5 or scrypt and verifies if it matches with stored password hash. If the stored hash matches the input-password hash, it returns 1. Otherwise, it's a 0.

Arguments

Takes in 2 string: $password and $hash generated by create_password_hash()

Return values

Boolean: This function returns a 1/0 (True or False)

delete_user ($user_ref)

delete_user() Creates a background job to delete the user

Arguments

Takes in the $user_ref of the user to be deleted

delete_user_task ($job, $args_ref)

delete_user_task() Background task that deletes a user. This function removes the user files, the email and re-assigns product edits to openfoodfacts-contributors-[random number]

Arguments

Minion job arguments. $args_ref contains the userid and email

is_admin_user()

Checks if the user with the passed user ID is an admin or not.

Arguments

The user ID is passed

Return values

Boolean: This function returns a 1/0 (True or False)

check_user_org($user_ref, $new_org)

This method checks a new org entry for a user.

warning: It has the side effect of already listing user in the org, and removing it from eventual previous one. If new_org is empty, user is removed from previous org.

It also creates the org if did not yet exists.

It should be called only by admin.

Parameters

User object $user_ref

String new org name $new_org

check_user_form($request_ref, $type, $user_ref, $errors_ref)

check_user_form() This method checks and validates the different entries in the user form. It also handles Spam-usernames, fields for the organization accounts.

This will then be used in process_user_form

Parameters

Request object $request_ref

String action type $type

edit / add / delete

User object $user_ref

Array to report errors $errors_ref

notify_user_requested_org($user_ref, $org_created, $request_ref)

Notify admin that a user requested to be part of an org

Parameters

User object $user_ref

boolean $org_created

Is the org newly created ?

Request object $request_ref

the request object

process_user_requested_org($user_ref)

A user requested to be part of a producer organization. Process it.

Parameters

User object $user_ref

process_user_form($type, $user_ref, $request_ref)

Process user form.

To be used after check_user_form

Parameters

String action type $type

edit / add / delete

User object $user_ref

Request object $request_ref

check_edit_owner($user_ref, $errors_ref)

This sets pro_moderator_owner according to request parameter. Sets it in $User global and $user_ref.

This variable is used to say that a moderator or admin is acting on the pro platform as part of a specific company.

Arguments

User object $user_ref

array to collect errors $errors_ref

migrate_password_hash($user_ref)

We used to use crypt instead of scrypt to store hashed passwords. If the user is logging in with a correct password, we can update the password hash.

Arguments

User object $user_ref

remove_old_sessions($user_ref)

Remove the oldest session if we have too many sessions opened for an user.

Arguments

User object $user_ref

generate_session_cookie($user_id, $user_session)

Generate a session cookie.

Arguments

User id $user_id

Session token $user_session

Return values

Session cookie.

open_user_session($user_ref, $request_ref)

Open a session, store it in the user object, and return a cookie with the session id in the request object.

Arguments

User object $user_ref

Request object $request_ref

Return values

The cookie is returned in $request_ref

is_ip_known_or_whitelisted ()

This sub introduces a server option to whitelist IPs for all cookies.

<<