OverviewObjectiveLearn to create, update, delete, and login users inProdigyView.Requirements Install version of ProdigyView with a database connectionEstimated Time10 Minutes www.prodigyview.com
Follow Along With Code Example1. Download a copy of the example code at www.prodigyview.com/source.2. Install the system in an environment you feel comfortable testing in.3. Proceed to examples/user/Users.php
Users….what about themA user…a better term would be end users… are probably thelife source of what ever you are building. Without saying, youneed a way to manage them. For this tutorial we are going tocover: Creating Users Logging In Updating Users Searching for Users Deleting UsersAspects such as user roles, content multi authors, roles,access levels, etc will come later.
Creating A User Creating a user is fairly simply. Fields are added to an array and passed to PVUsers::addUser() method. Technically the only field required is the user’s email but lets define some other fields. 1. Create the fields 2.Passwords will be MD5 encoded3. Pass arguments to addUser 4. If set to false, the password is not considered hashed and will be hashed
Attempt Login Now that we have a user and we want them to login with their email or username. Let’s give it a try.1. Pass the user’s email 2. Pass the user’s password in 3.Set the cookies on login 4. Check if the user is logged in www.prodigyview.com
Force LoginSometimes we need to forcefully log the user in withoutpassword verification. This can be done throughPVUsers::loginUser(). Either pass in the user’s name orthe user’s email. www.prodigyview.com
Retrieving the User InfoWe have a user in the database and will at some pointneed to retrieve their information. If the user’s email or idis known, their information can be retrieved through thosevalues.1. Retrieve a user’s information using their id 2. Retrieve a user’s information using their email
Searching For usersLet’s say we have multiple user’s with our growing siteand we need to somehow search for them based oncertain criteria. Take a look at the ProdigyView’sStandard Search Arguments and combined withPVUsers::getUserList we can get our results.
Updating A User User’s can be finicky. They want to update their info, change their image, etc. Fine, lets give them what they want. Updating fields can be accomplished by passing the users fields in an array to PVUsers::updateUser(). The only required field is the user’s id. 1. Retrieve the user’s information, returns an array2. Update a field in the array 3.Update the user using the array
And DeletingAfter all the trouble creating a users account, updatingtheir information, the free coffee, they decide they want todelete their account. Let’s comply. Delete a user using their id
Challenge!We know how to create, update and login a user. For thischallenge we do not want MD5 hashing of the passwordbut want to encrypt the password ourselves.Use PVSecurity to create a hashed password andattempt to login with that password.
The Not So Obvious1. When a user is deleted, content they are considered owner of is also deleted. This include subscriptions, points, content, options and relationships, categories and multi-author.2. When updating a user, it is best to retrieve and pass in the whole user document for that user. The reason is because fields that are left empty will be reverted to their default value.3. When a user is logged in, the data in that user’s row from the database is stored in session/cookie. The column’s name acts the key and columns value is the value stored. Ex: $user_email=PVSession::readSeassion(‘user_email’);
API ReferenceFor a better understanding of the users, visit the api byclicking on the link below.PVUsers More TutorialsFor more tutorials, please visit:http://www.prodigyview.com/tutorials www.prodigyview.com