Welcome Guest, Not a member yet? Register   Sign In
How is my progress?
#1

[eluser]Mutsop[/eluser]
Hi

Before I continue, sorry for this long post.

As I previously stated in another post I'm just a rookie.
So I wanted to ask you guys what you think of my application so far.

Is it well written? How about the placement of the files/code?
What would you do?

The following code has the basics of "CodeIgniter and Doctrine from Scratch" Series from phpandstuff

Oke so lets get started:
My application is a start of a cms system: Simple admin login and forgot password. When you forgot the password, a random new password will be emailed.

Login screen:
Quote:I created a table user for both the admins and users... I make the difference using a "user level" - 1 being the admin, 2 or above the normal users.
- When the form is being submit, the "submit" function is being called.
- In the submit function we have a "_submit_validate" function with form validations
- In the "_submit_validate" function we have a callback to authenticate

authenticate function in the login controller:
Code:
public function authenticate() {

        $isAuthenticated = Current_User::login($this->input->post('username'),
                                    $this->input->post('password'));
        $isAdmin = Current_User::user()->ulevel;
        if ($isAuthenticated == TRUE && $isAdmin == 1) {
            return TRUE;
            }
        return FALSE;
    }

Instead of duplicating the Current_User::login() model function, I kept the same code and added a user level check.

fyi in the user model I added
Code:
$this->hasColumn('ulevel', 'integer', 5);
in the setTableDefinition function.

And now for the diffcult part...

Forgot Password:
Quote:I have a simple form with one email imputbox and a submit button.
- When the form is being submit, the "submit" function is being called.
- In the submit function we have a "_submit_validate" function with form validations
- In the "_submit_validate" function we have a callback to forgot_password

forgot_password and _send_password from the forgot_password controller:
Code:
public function forgot_password() {

        $pass = Current_User::forgot_password($this->input->post('email'));
        $this->_send_password($pass, $this->input->post('email'));
    }
    private function _send_password($pass, $email) {

        $this->load->library('email');
        $this->email->from('[email protected]', 'apTest');
        $this->email->to($email);
        
        $this->email->subject('Reset Password - apTest');
        $this->email->message('Here is your new password: ' & $pass);    
        
        $this->email->send();        
    }

current_user model (partial):
Code:
public static function forgot_password($email) {
        if ($u = Doctrine::getTable('User')->findOneByEmail($email)) {
            $newPassword = Current_User::user()->reset_password();            
            $u->password = $newPassword;
            $u->save();
            return $newPassword;
        }
        return FALSE;
    }

user model (partial):
Code:
public function Reset_Password() {
        return $newPassword = random_string('numeric', 16);
    }

Now I'm kind of lost, if this is well programmed or not?. What do you think? Any opinion is appreciated Smile

Kind regards
#2

[eluser]Mutsop[/eluser]
Any help appreciated Smile

I know its alot to read but even a small hint would be welcome
#3

[eluser]Mutsop[/eluser]
I was hoping on some answer by now.

Anyone?

Regards
#4

[eluser]2think[/eluser]
Mutsop, don't be disheartened. A lot of the more experienced people on here are incredibly busy with their own private projects, work projects and other commitments so for them to go through a whole app or significant part thereof, it may take some time.

What I know works for me is if the app produces what you think are acceptable outcomes and passes any unit tests or use case testing, then you could consider it a fair success.

Also, don't forget that Doctrine is not the "default" DB ORM for Codeigniter so many people may not even know how to advise you (like me!)

However, my quick read of your Forgot_password controller code is that it seems elegant and what little I know about Doctrine, same goes for the model...but that's about all I can say with such a quick read and at this hour is that it seems "sensible".
#5

[eluser]Mutsop[/eluser]
I suppose you are correct... sorry for the rush Smile
But ain't Doctrine a well used ORM? I mean, when I check google and CI forums
Doctrine is one of the only ORM used.... I thought.

Also with the upcoming CI2 and Doctrine2 I suppose the working progress will be easier for most of the newcomers.

But to get back On Topic:
I know that when something works you might consider it a success. But it's like building a house. If you have all your functionalities it doesn't mean the house is well made. You won't be putting your kitchen on the top floor with a toilet in it. There has to be some simple rules to follow.




Theme © iAndrew 2016 - Forum software by © MyBB