insert user profile tank auth - codeigniter

I've seen question from this CodeIgniter: Passing fields to user_profiles database with Tank_auth
and my problem same as Davezatch have, but mine like this on auth controller:
...
if ($this->form_validation->run()) { // validation ok
if (!is_null($data = $this->tank_auth->create_user(
$use_username ? $this->form_validation->set_value('username') : '',
$this->form_validation->set_value('email'),
$this->form_validation->set_value('password'),
$this->form_validation->set_value('webiste'),
$email_activation))) {
...
when sending to my email, it show like this:
A PHP Error was encountered Severity:
Notice Message: Undefined variable:
new_email_key Filename: email/activate-html.php
Line Number: 14
any suggestion?
thank you

Looks like you are missing the new_email_key , that is used to activate the account. Check if it is present in your database also check your config for email activation .

Related

How to use SignedRoute on example of unique register URL

I created unique url registration, when someone uses link, he will be able to register to my app.
The only problem is, my signed route is invalid and gives 0 on hasValudSignature, where might be the problem?
My register function in RegisterController:
public function register(Request $request) {
abort_unless($request->hasValidSignature(), 403, 'That link has expired or is no longer valid!');
//they can register now
}
My URL generator:
$url = URL::temporarySignedRoute(
'register',
now()->addDays(7)
);
After using my user index view it is displayed on page so I can copy link for new user. However when I try to register using this link, at the end I've got information about wrong Validation (error I made by myself to prevent from registering unauthorized people)
Is my $url written wrongly?
Edit
For some reason after typing in console php artisan route:list
I've got error that
ReflectionException::("Class "UserController" does not exist")
How might this be possible?
Edit
After remakeing controller, I'm back to the original problem with hasValidSignature

laravel mutator: access other attributes

I have a plain Laravel 8 install, and added a mutator that should access other attributes of that model.
As an example: would like to set the name to the name + email address.
I tried:
public function setNameAttribute($value) {
$this->attributes['name'] = $value .' - '. $this->attributes['email'];
}
And test:
>>> User::factory()->make()
[!] Aliasing 'User' to 'App\Models\User' for this Tinker session.
<warning>PHP Warning: Undefined array key "email" in .../app/Models/User.php on line 45</warning>
=> App\Models\User {#3399
name: "Mr. Johathan Becker - ",
email: "dsteuber#example.com",
email_verified_at: "2021-05-07 18:10:35",
#password: "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi",
#remember_token: "bihwTV6T4E",
}
So: $this->attributes does not contain 'email'.
Can I access the other attributes of that model?
I can imagine that even if it is possible, the mutator can not guarantee that the related attribute is already set.
Update: matiaslauriti's comment solved the simplified example above. Thanks! The order in which the attributes are set matters. Afterwards I can use both $this->attributes['name'] or $this->name.
My more complex use case is: I want to create a Post for a User ($user->posts()->create([...])), and when setting a post attribute I want to access the 'user'. So in that case the user is already set and we can assume the 'user' is available. But in the Post mutator $this->user gives null. Suggestions?
You can try $this->email instead of $this->attributes['email']
Set email input before name input, and then you can access the email attribute with $attributes['email'].
I did it on the request file by
$this->request = collect(['email' => $this->email])->merge($this->request);

Laravel Email Greeting show Name instead of ID

Hello I wanted to ask regarding the Email Notification on Laravel, I have made a Status Notification wher I added this code
public function toMail($notifiable)
{
$leaveStatus=$this->leave->status;
if($leaveStatus==1){
$leaveNotify=" approved ";
}
else{
$leaveNotify=" declined ";
}
return (new MailMessage)
->subject('Leave Status')
->greeting('Hello '.$this->leave->user_id)
->line('I hope you are doing well')
->line('Your requested leave of' . $this->leave->type. ' type has been ' .$leaveNotify)
->line('Leave type: ' .$this->leave->type)
->line('From dt :' .$this->leave->from)
->line('To dt :' .$this->leave->to);
}
This works very well the email is being sent in each change on a Leave Application so what I am looking for is the part of the greeting , the
greeting('Hello '.$this->leave->user_id)
It shows the ID of the user instead of the first_name(which is a filed for the name) I have tried adding a ->first_name after the user_id but then it returns an error, the user_id doesn't have a foreign key that connects it with the users table its just a field which stores the id of each authenticated users but it works all the way here so im not sure that is the problem
You can use the notifiable variable passed into the function, which is the user the email is being sent to.
->greeting('Hello '.$notifiable->first_name)
You need to add relation for user in that model. See https://laravel.com/docs/7.x/eloquent-relationships . After that call it via $this->leave->user->first_name

How to authenticate user with firebase sdk

I am using this SDK and following this documentation. Now I am trying to create and authenticate user in firebase db. How can I do that.I am doing the project in Codeigniter and in my controller I did this:
public function register()
{
$firebase = (new Firebase\Factory())->create();
$tokenHandler = $firebase->getTokenHandler();
$uid = 'a-uid';
$claims = ['foo' => 'bar']; // optional
// Returns a Lcobucci\JWT\Token instance
$customToken = $tokenHandler->createCustomToken($uid, $claims);
echo $customToken; // "eyJ0eXAiOiJKV1..."
$idTokenString = 'eyJhbGciOiJSUzI1...';
// Returns a Lcobucci\JWT\Token instance
$idToken = $tokenHandler->verifyIdToken($idTokenString);
$uid = $idToken->getClaim('sub');
echo $uid; // 'a-uid'
}
and I call the function It gave me this error:
Type: Kreait\Firebase\Exception\ServiceAccountDiscoveryFailed
Message: Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "FIREBASE_CREDENTIALS" is not set. Kreait\Firebase\ServiceAccount\Discovery\FromEnvironmentVariable: The environment variable "GOOGLE_APPLICATION_CREDENTIALS" is not set. Kreait\Firebase\ServiceAccount\Discovery\FromGoogleWellKnownFile: The well known file is not readable or invalid
Filename: E:\xampp\htdocs\firebasedb\vendor\kreait\firebase-
php\src\Firebase\ServiceAccount\Discoverer.php
Line Number: 48
Can anyone help me with this issue? Any kind of help are appreciated. Thanks.
EDIT
Okay I solve this problem with default .json file path like this:
$serviceAccount = ServiceAccount::fromJsonFile(JSON_FILE_PATH.'google-service-account.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
Now can I register a new user from web-app? Can anyone Help please. I have been stopped in this problem since long. Helps are highly appreciated.
You Set JSON Key environment variables
FIREBASE_CREDENTIALS GOOGLE_APPLICATION_CREDENTIALS ?
try reading this Firebase Admin SDK for PHP Setup
From the documentation https://firebase-php.readthedocs.io/en/latest/authentication.html#authenticate-with-admin-privileges
There two crucial points to note.
Many use cases for verifying ID tokens on the server can be accomplished by using Security Rules for the Firebase Realtime Database and Cloud Storage. See if those solve your problem before verifying ID tokens yourself.
The ID token verification methods included in the Firebase Admin SDKs are meant to verify ID tokens that come from the client SDKs, not the custom tokens that you create with the Admin SDKs Check out https://firebase.google.com/docs/auth/users/#auth_tokens
About Users:
From https://firebase-php.readthedocs.io/en/latest/user-management.html
You have a sample
$request = \Kreait\Auth\Request\CreateUser::new()
->withUnverifiedEmail('user#example.com')
->withPhoneNumber('+15555550100')
->withClearTextPassword('secretPassword')
->withDisplayName('John Doe')
->withPhotoUrl('http://www.example.com/12345678/photo.png');
$createdUser = $auth->createUser($request);
Please Note:
By default, Firebase Authentication will generate a random uid for the new user. If you instead want to specify your own uid for the new user, you can include in the properties passed to the user creation method:
$properties = [
'uid' => 'some-uid',
// other properties
];
$request = \Kreait\Auth\Request\CreateUser::new()
->withUid('some-uid')
// with other properties
;
I had same problem with Laravel in my case, here is the solution:
First save the .json credentials file you got from Firebase project into the root of your Laravel app on the same level as .env file.
The json file looks like you-file-firebase-adminsdk-0000-9845985498a.json
Then open the .env file and create a new environment variable and paste the json credential file name.
FIREBASE_CREDENTIALS=../you-file-firebase-adminsdk-0000-9845985498a.json

Problem getting codeigniter library for google reader to work when trying to log in and get feed data

I'm trying to getting this http://www.forgottenexpanse.com/projects/ci_reader CodeIgniter library for interacting with Google Reader to work.
When following the examples on the page, this works fine:
$this->load->library('reader');
$shared_items = $this->reader->shared_items('12006118737470781753');
foreach ($shared_items['items'] as $entry) {
echo $entry['title'];
}
But when trying to grab non-public data by loging in:
$this->load->library('reader');
$credentials = array('email' => 'me#gmail.com', 'password' => 'mypassword');
$this->reader->initialize($credentials);
$shared_items = $this->reader->shared_items();
foreach ($shared_items['items'] as $entry) {
echo $entry['title'];
}
I get a bunch of warnings related to line 454 of libraries/Reader.php, like this one:
Message: simplexml_load_string(): Entity: line 128: parser error : StartTag: invalid element name
I'm hoping someone has an idea what might be happening here.
Thanks much!
The library you point to still uses the SID cookie to authenticate with Reader. That was deprecated a few months ago. The new preferred authentication schemes are either OAuth or ClientLogin with an authentication token; both are described at http://code.google.com/p/google-reader-api/wiki/Authentication.
In this particular case, you'll have to modify the _login function to get the Auth token out of the ClientLogin response. Once you have it, you'll also need to modify the _fetch function to include it as the Authorization header (instead of adding the cookie).

Resources