Editing Users in Admin Backend

Report issues with Enuuk Auction Platform or Mods here - remember to raise a ticket with phpauction.net as well
Post Reply
RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Editing Users in Admin Backend

Post by RWAP » Thu Jul 11, 2013 2:38 pm

If you try to edit the email of a user in the admin backend, and happen to use an existing email address, you see the generic SQL error

Code: Select all

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'info@example.com' for key 2
rather than a nice error message to say that the email address is already in use.

You need to change the following code in class\Action\Admin\User.php

Find the function edit() and then find:

Code: Select all

                $user->saveToDB($this->db);
                $this->context->message = _('User data updated successfully');
                $this->defaultAction();
                return true;

            }catch(Exception $e){
                if($e->getCode()==Error::BY_USER){
                    $this->context->status = false;
                    $this->context->errorMessage = $e->getMessage();

                    // Custom user fields
                    if(count($customFields)){
                        foreach($customFields as $k=>$v){
                            $key = 'custom'.$v['id'];
                            $v['value'] = $par[$key];
                            $customFields[$k] = $v;
                        }
                    }
                    $data['customFields'] = $customFields;
Add below this:

Code: Select all

                }elseif($e->getCode() == 23000){
                    $this->context->status = false;
                    $this->context->errorMessage = _('E-mail address already used');

                    // Custom user fields
                    if(count($customFields)){
                        foreach($customFields as $k=>$v){
                            $key = 'custom'.$v['id'];
                            $v['value'] = $par[$key];
                            $customFields[$k] = $v;
                        }
                    }
                    $data['customFields'] = $customFields;

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests