I am developing payroll management with codeigniter. I will tell the design briefly.
I have single db. In that db, multiple clients are registered. Till now we provided single login form for clients by prompting username, password and client ID. But customer asking to give unique URL's for each and every client with out duplicating code and with single db.
For example: http://www.example.com/Client1, http://www.example.com/Client2 etc
So that client can enter username and password only. Based on the client code in url, we can validate username and password.
Just i want to know this is possible or not. Any problems will come in future?
Thanx
i got it
you can handle it from routes
in your routes file just call your database
$db =& DB();
$db->select('employe_name');
$query = $db->get( 'tbl_user' );
$result = $query->result();
foreach( $result as $row )
{
$route[ $row->name_prefered ] = ' http://www.example.com/dashboard';
now what acutely happens is when ever http://www.example.com/dashboard link hits it will change to http://www.example.com/employe name
Related
Below is my code snippet. I want to reduce the balance of a user in the database using Codeigniter 4?
dd($this->ionAuth->update($this->ionAuth->users()->row()->id, ['balance' => 1000]));
*I'm using Ion Auth for updating.
It's just a big burden when updating the database using modelling data.
It looks like you intend to use $this->ion_auth->user() instead of $this->ion_auth->users().
Also keep in mind that executing a dump and die on $this->ion_auth->update(...) returns a boolean not the updated user data.
References:
users() gets all users.
users()
Get the users.
Parameters
'Group IDs, group names, or group IDs and names' - array OPTIONAL. If an array of group ids, of group names, or of group ids and names are passed (or a single group id or name) this will return the users in those groups.
Usage
$users = $this->ion_auth->users()->result(); // get all users
user() gets a single user.
user()
Get a user.
Parameters
'Id' - integer OPTIONAL. If a user id is not passed the id of the currently logged in user will be used.
Usage
$user = $this->ion_auth->user()->row();
echo $user->email;
look here authentcate library for ci4
https://github.com/lonnieezell/myth-auth
go there download it
ionAuth is not compablitablke with ci4
I need to create to send a message to all new users registered on my website. I created a table called messages that admins can store (insert) the messages from the admin panel to this table and these messages are simply shown to all users with a foreach.
I don't know if this the best way to do something like that!
Anyway, the problem is that when any new user register and open his dashboard he just found the old messages
This is the table :
image
And this is the simple code for foreach
$msgForAll = Message::latest()->get();
I'm not sure how to display new messages to the users.
Again the way I made this idea is wrong, I know that ):
You can use eloquent's where spefically the whereDate queries in your case to get certain rows past or before date.
As an example relating to what you want to do, it can be along the lines of this:
// Given that you are using Auth to get the user's data...
// Get messages that were created after the user's creation date
$messages = Message::whereDate('created_at','>',Auth::User()->created_at)->get();
I would like to ask about logging in to Laravel but in a different way:
User information including the password but not the email will be stored in users table, while email_address will be stored in a email_addresses table with a boolean field called is_default.
So the user can have several emails, but he can log in with only one email that has the is_default is true. and he could change his default email through his profile.
So, how can I make the login process through the Auth::login() facade.
I was able to register the user by storing the information in a users table and store his email_address and is_default = true in the email_addresses table.
It can be a little tricky. Auth::login() just needs to fetch email and password, so if you can trick the model into thinking it has an email field accessible via $user->email, things will work out:
public function getEmailAttribute()
{
return DB::table('email_addresses')->whhere('default', 1)->where('user_id', $this->id)->first()->toArray()['email'];
}
I have used laravel boilerplate for login.
I have worked using virtual host and put information on basis of virtualhost.
I have 2 tables:
1. users
2. social_logins
Actually i am authenticating from users table. I need to store information in users and then link it with social_logins user_id i.e, store information in table 2.
The main problem here is it doesn't store data in table. This line is not working:
return $this->getAuthorizationFirst($provider);
I have put redirect so it will redirect to given route but doesn't store data in database.
if I catch callback in controller I can catch the information.
$user = Socialite::driver('facebook')->user();
I have done normally using Socialite plugin in normal laravel, but i don't have any idea in Boilerplate.
Actual lifecycle of this loginThirdParty trait is:
1 The first time this is hit, request is empty
2 It's redirected to the provider and then back here, where request is populated
3 So it then continues creating the user
So If the provider is not an acceptable, this trait kick back. Hopefully you need to recheck your .env for FACEBOOK_CLIENT_ID, FACEBOOK_CLIENT_SECRET and CALLBACK_URL.
I am new to Object Model Mapping and just read the documentation of the CodeIgniter DataMapper. I have tried the examples and I am quite impressed in how little time one can achive a lot.
But I don't seem to get one problem solved:
Lets say I have two tables: customer and address. A customer can have many addresses but am address only one customer.
Now, I have a registration form where a new customer has to enter his personal data which is stored in the customer table and his address which is stored in the address table.
Validation is done in the specific models. My problem is how can I ensure that the data is valid for both tables prior to saving them to database.
At the moment it is possible that the customer enters the correct data for the customer table which validates and gets saved to db but the address data does not validate and is not saved.
In short: I only want to save the data of any table to db if the data for all tables validates else I want to get the error messages.
Thanks for any help in advance.
First way is to use transactions, second - validate both address and customer data, and if both is valid - store.
It's not clear from the documentation, but you can call the validate() method prior to calling save():
public function test()
{
// Customers require an email address
$cust = new Customer();
$cust->first_name = "Me";
$cust->validate();
if ($cust->error->string)
{
echo $cust->error->string;
// outputs The Email Address field is required.
}
else
{
// validation passed, save customer and related address to db
$cust->save(array($address));
}
}
If you have validation rules defined, you don't need to explicitly call validate(), the validation rules will also be checked when you call save().
In case validation failed, save() will return FALSE, after which you can check $this->valid to see if a validation error caused the save to fail.