Customizing Tank_Auth table field names for CodeIgniter - codeigniter

I am a beginner learning codeigniter to build a website. For authentication feature, i use tank_auth library and it works fine if I dont alter the tank_auth table field names.
Then, to combine the tank_auth's 'users' table with my existing 'users_info' table, I modified the field names 'new_email_key' and 'username' as NewEmailKey and UserName respectively.
The above specified field name changes were done in libraries\Tank_auth.php, models\tank_auth\users.php and controllers\auth.php files.
In the database, the submitted data are stored right in the table. But in the activation email received, i am getting the following errors:
Message: Undefined variable: username
Filename: email/activate-html.php
Message: Undefined variable: new_email_key
Filename: email/activate-html.php
Is it safe to use the tank_auth table field names as it is in our CI projects?
Is there any clear documentation written on how to customize and use the tank_auth 'users' table field names?
I am stuck with these error messages as i dont figure out where else the field names need to be altered in tank_auth.
Any help appreciated.

These errors you are listing are simple "undefined variable" errors, like it says, I'm not sure what is confusing here.
Have you looked at the mailing function? Or googled the error meaning? Tank Auth's mail uses an array for sending mail.
$data['username'] = "Bob";
$data['new_email_key'] = "1249ufasiojlk215ifasdy243jhaslkjhasjkghasd";
mail_function_name($data)
that data is passed to the mail function which uses the /email/activate-html.php view/template.
I don't believe there is Tank_Auth modification documentation as the PHP is VERY straight forward, and well commented, if you are having trouble with it, it means you don't understand the code, and the fault lies in your ability to understand WHAT is being done in the code, not in the documentation of TankAuth. Documentation won't really save you here.
Learn what the errors are (ie, undefined variable) and try to fix them one by one.

Since Tank_auth's documentation does not seem to mention config setting for this,
sending such an error message is unexpected and may be taken as a bug.

Related

Maatwebsite/Laravel-Excel exports blank excel when using Input::get() in model

I developed a Laravel application that connects to a external MySQL database for reports. I'm using Maatwebsite/Laravel-Excel 3.1 to be able to export to excel.
In this app, I have a method in my model that uses Input::get() for 3 variables ($from, $to, $paymentType). This method is called whenever the user chooses date range and payment type as filter for their reports. Everything works as it should since data is displayed in my view.
Now this same method is called when the user chooses to export the file to excel. Again, all that works except the files is blank.
The curious thing is that if I replace all Input::get() for static values such as '2018-11-14' for the dates and 'n' for payment type, then the file exports with data.
I've been struggling with this for a couple of days so I hope someone can help me.
Thanks,
Ernesto
First, towards the top of the controller file, add:
use Illuminate\Http\Request;
Then, you can access the fields by:
$request->input('from');
$request->input('to');
Assumption: from and to are correct field names.
You can also use request()->input('from') etc. directly (note the absence of $).
Please see this for more info: https://laravel.com/docs/5.6/requests
If the parameters are obtained from the request you should use $request->input() instead of Input::get().
If used in a function where $request is not available you could use request('variable') to get the variable value from the request.

In #ngxs/form-plugin, what is the definition of the properties mentioned in the example?

Please expand your NgxsFormPluginModule description on gitbook.
I just implemented a reactive forms example with #ngxs/form-plugin.
It works great, but it was a bit of a struggle to get it to work; because it was not clear to me that the form state must have these specific properties:
model: YourFormModel,
dirty: boolean,
status: string,
errors: {}
Maybe you could add an explanation of these properties and their intended use?
What are the possible values for status, or is this up to the developer to define?
What type of object is errors and what is it used for? It appears to be empty even when validation fails. errors would suggest it is an array, but the example defines the default as an object?
I am posting this as a question because of your answer here: Where is it best to post questions about ngxs?
status field is supposed to store latest status of FormGroup.
You can see the code that is responsible for its update here.
The possible values for status are defined here.
errors is supposed to contain validation errors for the whole form group.
Its type is ValidationErrors since it's supposed to copy errors from the corresponding form group.
The code responsible for its update is supposedly here.
But there's an unsolved issue with filling it with actual error data., so it's not available yet and you'll have to rely on controls' error data.

CakePHP Auth Loads Too Many Session Variables

Using CakePHP2.0 Beta I managed to write a custom login handler for my existing database schema. All's well, except that upon logging in I printed out the session variables stored and what Cake's Auth component did is store the entire record from the "Member" table (where my usernames+hashes come from) in session. It is storing an array with data fields that are totally irrelevant to the session. For instance it stores the date the member was created, their address, etc. All pretty useless information for me as I basically only need their ID and maybe username, name, email address.
The offending lines for me are found in: /lib/Cake/Controller/Component/AuthComponent.php line 512. It states,
$this->Session->write(self::$sessionKey, $user);
So my custom authenticate component returns $user and it throws this whole thing into the session. Now, I don't want to go about editing in the core libraries because this project is definitely going to be upgraded when 2.0 comes out. Is there any way to store less information in sessions? I want to keep this whole thing more lightweight.
Possible solution: Change my custom authentication component to only return the fields I need into the $user variable. Are there any concerns about what data I should/shouldn't be returning?
I've solved the problem using my "possible solution". In /app/Controller/Component/auth/MyController.php, I changed the "ClassRegistry::init($userModel)->find" method to have a parameter for 'fields' where I specify only the fields I need. Works like a charm.

How to get error messages from model

Say you have a User model. The controller is attempting to create a new User. Should the controller check that the username is valid, and the password is long enough, and the first and last name are filled out, etc? Or should you pass all that data straight to the User model via a Create method? The Create method would then return a true on success, or false on failure?
If it's the latter (and I think it is), how do the error messages get sent back to the controller (so they can be displayed in a view)? Should you pass an errors array to the Create method which the model augments? Or should the model keep an internal store of errors, with appropriate accessors? I don't like either method...is there a better way?
These errors don't seem exceptional, so I don't think exception handling is appropriate.
Edit: I'm using PHP for this project, but I use Python too.
For the first question, the model should do the verifications (and use some form of error handling to notify the controller and view that errors did or did not occur). For the second, it depends on what programming language / framework you are using... What are you using?

Setting and reading a session

I have a couple of classic ASP pages that require a user to enter their email and a specified 'keycode' that they have been given in order to gain access to a voucher that they can have emailed to them.
A voucher code is then dynamically generated and (currently) sent in the query string of the url to a second page that would then give the user the option to have the voucher emailed.
I now want to change this so that the voucher code is set as a session, rather than passing it via the url. But i'm having trouble trying to set the session.
I have pasted the code here in a Gist on github: http://gist.github.com/187622
The code errors on Line 47 as follows;
Microsoft VBScript runtime error '800a01a8'
Object required: 'Session'
/bennettsget/default.asp, line 47
I was wondering if anyone would be able to help? Apologies if my explanation or terminology is not correct. Classic ASP is not my language of choice, but it is one of those sites you inherit when starting a new job.
Thank you.
Remove the word "Set". Try
Session("fullcode") = fullcode
Set is usually used in conjunction with a full-blown object. When you're working with a Session, you're really setting a value for a collection rather than the creation of an object.

Resources