Page 1 of 1

A user with such an e-mail is already registered...

PostPosted: 18 Apr 2016, 23:36
by mpower2k
I have disabled user registration and when someone uses the booking form, if it already used it in the past I get the error:
A user with such an e-mail is already registered. Please login and try again.

What should I modify so that it doesn't check if the email was already used so it permits the user to submit the form multiple times with the same email address?

Thanks!

Re: A user with such an e-mail is already registered...

PostPosted: 20 Apr 2016, 11:08
by Foton
In the file protected\modules\booking\controllers\MainController.php change code from
Code: Select all
$userData = User::createUser(array(
                            'email' => $booking->useremail,
                            'username' => $booking->username,
                            'phone' => $booking->phone,
                            'activatekey' => User::generateActivateKey()
                        ));

                        if ($userData) {
                            $user = $userData['userModel'];
                            $user->id = $userData['id'];
                            $user->password = $userData['password'];
                            $user->email = $userData['email'];
                            $user->username = $userData['username'];
                            $user->activatekey = $userData['activatekey'];
                            $user->activateLink = $userData['activateLink'];

                            if($payImmediately){
                                $identity = new UserIdentity($userData['email'], $userData['password']);
                                if($identity->authenticate() && Yii::app()->user->login($identity, 2592000)){
                                    Yii::app()->user->setState('attempts-login', 0);
                                    User::updateUserSession();
                                    User::updateLatestInfo(Yii::app()->user->id, Yii::app()->controller->currentUserIp);
                                }
                            }

                            $notifier = new Notifier;
                            $notifier->raiseEvent('onNewUser_'.param('user_registrationMode'), $user, array(
                                'user' => $userData['userModel'],
                                'forceSendUser' => true
                            
));
                        } else {
                            $booking->addError('', tt('Error User Registration', 'booking'));
                        } 

to
Code: Select all
if(param('useUserRegistration', 1)) {
                        $userData = User::createUser(array(
                            'email' => $booking->useremail,
                            'username' => $booking->username,
                            'phone' => $booking->phone,
                            'activatekey' => User::generateActivateKey()
                        ));

                        if ($userData) {
                            $user = $userData['userModel'];
                            $user->id = $userData['id'];
                            $user->password = $userData['password'];
                            $user->email = $userData['email'];
                            $user->username = $userData['username'];
                            $user->activatekey = $userData['activatekey'];
                            $user->activateLink = $userData['activateLink'];

                            if($payImmediately){
                                $identity = new UserIdentity($userData['email'], $userData['password']);
                                if($identity->authenticate() && Yii::app()->user->login($identity, 2592000)){
                                    Yii::app()->user->setState('attempts-login', 0);
                                    User::updateUserSession();
                                    User::updateLatestInfo(Yii::app()->user->id, Yii::app()->controller->currentUserIp);
                                }
                            }

                            $notifier = new Notifier;
                            $notifier->raiseEvent('onNewUser_'.param('user_registrationMode'), $user, array(
                                'user' => $userData['userModel'],
                                'forceSendUser' => true
                            
));
                        } else {
                            $booking->addError('', tt('Error User Registration', 'booking'));
                        }
                    } 


in files protected\modules\booking\models\Booking.php and protected\modules\booking\models\SimpleformModel.php change code from
Code: Select all
public function myUserEmailValidator() {
        if (Yii::app()->user->isGuest) { 

to
Code: Select all
public function myUserEmailValidator() {
        if (Yii::app()->user->isGuest && param('useUserRegistration', 1)) { 

in file protected\modules\bookingtable\models\Bookingtable.php change code from
Code: Select all
public static function addRecord(Booking $booking, User $user, $status = self::STATUS_NEW) {
        $dateStart = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($booking->date_start, Booking::getYiiDateFormat()));
        $dateEnd = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($booking->date_end, Booking::getYiiDateFormat()));

        $model = new Bookingtable;
        $model->active = $status;
        $model->apartment_id = $booking->apartment_id;
        $model->username = $booking->username;
        $model->email = $booking->useremail;
        $model->phone = $booking->phone;
        $model->date_start = $dateStart;
        $model->date_end = $dateEnd;
        $model->time_in = $booking->time_in;
        $model->time_out = $booking->time_out;
        $model->comment = $booking->comment;
        $model->user_ip = $booking->user_ip;
        $model->user_ip_ip2_long = $booking->user_ip_ip2_long;
        $model->sender_id = $user->id;
        $model->amount = $booking->amount;
        $model->num_guest = $booking->num_guest;

        $model->save(false);

        return $model;
    } 

to
Code: Select all
public static function addRecord(Booking $booking, $user, $status = self::STATUS_NEW) {
        $dateStart = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($booking->date_start, Booking::getYiiDateFormat()));
        $dateEnd = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($booking->date_end, Booking::getYiiDateFormat()));

        $model = new Bookingtable;
        $model->active = $status;
        $model->apartment_id = $booking->apartment_id;
        $model->username = $booking->username;
        $model->email = $booking->useremail;
        $model->phone = $booking->phone;
        $model->date_start = $dateStart;
        $model->date_end = $dateEnd;
        $model->time_in = $booking->time_in;
        $model->time_out = $booking->time_out;
        $model->comment = $booking->comment;
        $model->user_ip = $booking->user_ip;
        $model->user_ip_ip2_long = $booking->user_ip_ip2_long;
        $model->sender_id = $user ? $user->id : 0;
        $model->amount = $booking->amount;
        $model->num_guest = $booking->num_guest;

        $model->save(false);

        return $model;
    }