How to Display Specific User information in cakephp..? - cakephp-2.0

Iam new to cakephp and i have a problem with an element. how to display each user account information when ever the user loggedin than click on myaccount link how will show the particular user details. myaccount link is in element.
Finally How to display specific user information when click on the myaccount link. The myaccount link is in element file.

If you want to display the logged In users information in their account page.Then you simply do it by using Session. Cause in CakePHP logged in user's are stored into session.
In this case you can try var_dump($this->Session->read('Auth.User'));, here you can see the logged in users information. And now you can populate users information form it.

If you want login user data then, After your successfully login your user data will be store in Auth User session.
So if you want to fetch whole user data then you can try var_dump($this->Session->read('Auth.User'));
Or
If you want any single field from your login user table then you can use like,
$this->Auth->user('id')
here instead of 'id' you can use any field name of users(where you store your user credentials and details) table.
Make sure your login user data stored in the authentication table i.e if you are storing only username and password in users table and the other details stored in another table with name user_details, then you can not fetch user_details for the login user.
for that you need to store user_details in Auth.User session after login.
I hope this will be helpful for you.

Related

Best way to implement one-time feature after signup?

Note: This is likely a duplicate question but I couldn't search for a solution/suggestion for my use case, so if anyone can re-direct me, that would be appreciated.
Problem: I have a NextJS application that runs on Prisma ORM and MySQL database. I am using NextAuth for OAuth authentication for sign up and log in.
So far the application works just fine but I want to check whether a user is logging in for the first time and redirect them to a set up page whether they would input personal details in order to populate a table on the database, so that the app can form a dynamic page based on their newly added information.
On the database, there are the user table (populated by NextAuth immediately at login) and the profile table.
Under NextAuth, the user table is populated automatically with the account's user name and email etc. However, that is not a unique entry and NextJS getStaticPath requires a unique entry to generate a dynamic page. That's why I have created the profile table to allow users to add their custom username where the dynamic URL will be generated (e.g. localhost:3000/u/[slug])
Here's my question - I want to check that the user is first time logging in and send a form for them to fill out the necessary information to input data onto the profile table, otherwise they would go straight to their profile homepage. What is the best way to check that and to redirect them to that form page?
Do I do it at server side with getServerSideProps by checking that the id from user table is missing from the profile table and do a redirect? Or is there some method that's customarily used to implement this "initial set-up" procedure?

Wordpress user registration to upload data for admins approval

I want that users be able to upload info, this info will be show on a product list but it will only be posted if the admins approve it.
The user may need to register or not, the contact info will be on the info they upload.
Do i need to storage the info on a different database? can i do this with the wordpress registration?
You can use wordpress database table user to store data, set post_status as 'pending', so that admin can check and can change its status to 'publish'
You can create custom template page, then insert user data in post table using custom query or
wp_insert_post() function.
Hope this helps.
Cheers!!!!

cakephp add associated model on manual login

In cakephp I have two Models User and Account, User belongsTo Account model, now on logon by cakephp UsersController->login method the the associated table automatically added to session variable but when I manually login by $this->Auth->login($user['User']) only User Model data added in the Session variable, how can I achieve Account data Session on manual login?
Manually logging in using $this->Auth->login($data); will populate the session with $data, as stated in the documentation: http://api.cakephp.org/2.5/class-AuthComponent.html#_login
The solution is to login all the data you want. In your case:
$this->Auth->login($user);
Where $user contains the Account data.
I found another way to doing this, all I need to find user and login by method :$this->Auth->login($user);
, now for manual login I have to set all components so I use $this->Session->write('Auth.User', $user); to write all data in session Component which add Associated tables in Session.

How to create single user login page?

i want to create a user account using asp page in which only one user can login their account ,if that page is currently logged then no one can log in that page after log out only another user can log in that account
This may give you glimps, in database you may add a table UserLogin with two fields UserId, IsLogin. While loggin in any user check for islogin status if it returns true then dont allow user to login. If returns false then allow user to get login. After successful login switch islogin state true.
Hope I have understand your question.
Darshan Joshi's answer is one way to do it, and if you have a simple enough application it may be sufficient.
Depending on the specifics of your application, you might want to think about different angles.
For example: If more than one distinct page needs to only take one user at a time, I would think about creating a new table with a record for each of these pages. This way, you can set a page as logged-in/in-use using the user's unique ID when someone logs in or access the page. When the user logs out/leaves the page (or if their ASP Session expires- users do not always log out cleanly!) you can "unlock" the page again. Not only that, you might reduce database load by searching specifically for the page record rather than any user with a logged-in flag.

CakePHP 2.1 - AuthComponent::user() only gives me ID, Email, Password (hashed)

I'm trying to use AuthComponent::user('first_name') to access the users firstname and show it in a view. If I do debug(AuthComponent::user()); I see that I can only access the ID, Email and password of the currently logged in user but not his name etc.
Do I have to specify which userdata is available when the user is logged in or should this happen automatically?
The session is filled on the $this->Auth->login() call.
Everything you commit to this Method is stored in the session.
Also see the API:
http://api20.cakephp.org/class/auth-component#method-AuthComponentlogin

Resources