Creates new account (register new user) and a credential for it

@param Pluf_HTTP_Request $request
@param array $match
@return User_Account created account
482443
public static function create($request, $match)
    {
        // Create account
        $extra = array();
        $data = array_merge($request->REQUEST, $request->FILES);
        // $form = new User_Form_User($data, $extra);
        // $cuser = $form->save();
        $usr = User_Account::getUser($data['login']);
        if ($usr) {
            throw new Pluf_Exception('Username is existed already.', 400);
        }
        if (! ($request->user->hasPerm('tenant.owner') || $request->user->hasPerm('user.manager')) 
                || ! array_key_exists('is_active', $data)) {
            $account_active = false;
            if (class_exists('Tenant_Service')) {
                $account_active = Tenant_Service::setting('Module.User.account_auto_activate', false);
            }else{                
                $account_active = Pluf::f('user_account_auto_activate', false);
            }
            $data['is_active'] = $account_active;
        }
        $form = new User_Form_Account($data, $extra);
        $cuser = $form->save();
        // Create credential
        $credit = new User_Credential();
        $credit->setFromFormData(array(
            'account_id' => $cuser->id
        ));
        $credit->setPassword($data['password']);
        $success = $credit->create();
        if (! $success) {
            throw new Pluf_Exception('An internal error is occured while create credential');
        }
        if (! Pluf::f('user_account_auto_activation', false)) {
            // TODO: hadi, 1397-05-26: send mail to activate account by user
        }
        // Return response
        return $cuser;
    }
487037
public static function get($request, $match)
    {
        $discount = Discount_Views_Discount::getDiscount($request, $match);
        // حق دسترسی
        // CMS_Precondition::userCanAccessContent($request, $content);
        // اجرای درخواست
        return new Pluf_HTTP_Response_Json($discount);
    }
1361232
public function password($request, $match)
    {
        $msg = array(
            'message' => 'succcess'
        );
        // TODO: maso, 2017: recover by mail
        if (array_key_exists('email', $request->REQUEST)) {
            $sql = new Pluf_SQL('email=%s', array(
                $request->REQUEST['email']
            ));
            $user = $request->user->getOne($sql->gen());
            if ($user) {
                $this->sendPasswordToken($request, $user);
            }
            return $msg;
        }
        // TODO: maso, 2017: recover by login
        if (array_key_exists('login', $request->REQUEST)) {
            $sql = new Pluf_SQL('login=%s', array(
                $request->REQUEST['login']
            ));
            $user = $request->user->getOne($sql->gen());
            if ($user) {
                $this->sendPasswordToken($request, $user);
            }
            return $msg;
        }
        // Reset password by token
        if (array_key_exists('token', $request->REQUEST)) {
            $token = new User_PasswordToken();
            $sql = new Pluf_SQL('token=%s', array(
                $request->REQUEST['token']
            ));
            $token = $token->getOne($sql->gen());
            if (! $token || $token->isExpired()) {
                throw new Pluf_Exception_DoesNotExist('Token not exist');
            }
            $user = $token->get_user();
            $user->setPassword($request->REQUEST['new']);
            $user->update();
            $token->delete();
            return $msg;
        }
        // Reset password by old password
        if (array_key_exists('old', $request->REQUEST) || array_key_exists('old_password', $request->REQUEST)) {
            $oldPass = array_key_exists('old', $request->REQUEST) ? 
            $request->REQUEST['old'] : $request->REQUEST['old_password'];
            if ($request->user->isAnonymous()) {
                throw new Pluf_Exception_Unauthorized();
            }
            // Retreive credential
            $cred = User_Credential::getCredential($request->user->id);
            if (! $cred->checkPassword($oldPass)) {
                throw new Pluf_Exception_MismatchParameter('Old pass is not currect');
            }
            $newPass = array_key_exists('new', $request->REQUEST) ? 
                $request->REQUEST['new'] : $request->REQUEST['password'];
            $cred->setPassword($newPass);
            $cred->update();
            return $msg;
        }

        throw new Pluf_Exception_MismatchParameter('Invalid request params');
    }
306163
public function updateAccount($request, $match)
    {
        $model = Pluf_Shortcuts_GetObjectOr404('User_Account', $request->user->id);
        $form = Pluf_Shortcuts_GetFormForUpdateModel($model, $request->REQUEST, array());
        return $form->save();
    }
816235
public function find ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        $count = 10;
        $pag = new Pluf_Paginator(new SaaSKM_Vote());
        $pag->list_filters = array(
                'voter'
        );
        $sql = new Pluf_SQL('tenant=%s AND owner_class=%s AND owner_id=%s', 
                array(
                        $request->tenant->id,
                        'Geo_Location',
                        $location->id
                ));
        $pag->forced_where = $sql;
        $list_display = array(
                'vote_value' => __('location title'),
                'vote_comment' => __('description')
        );
        $search_fields = array(
                'voter',
                'vote_comment'
        );
        $sort_fields = array(
                'voter',
                'creation_date',
                'modif_dtime'
        );
        $pag->configure($list_display, $search_fields, $sort_fields);
        $pag->items_per_page = $count;
        $pag->sort_order = array(
                'creation_dtime',
                'DESC'
        );
        $pag->setFromRequest($request);
        return new Pluf_HTTP_Response_Json($pag->render_object());
    }
223970
public function create($request, $match)
    {
        // initial content data
        $extra = array(
            'user' => $request->user,
            'model' => new CMS_Content()
        );

        // Create content and get its ID
        $form = new CMS_Form_ContentCreate($request->REQUEST, $extra);

        // Upload content file and extract information about it (by updating
        // content)
        $extra['model'] = $form->save();
        $form = new CMS_Form_ContentUpdate(array_merge($request->REQUEST, $request->FILES), $extra);
        try {
            $content = $form->save();
        } catch (Pluf_Exception $e) {
            $content = $extra['model'];
            $content->delete();
            throw $e;
        }
        return $content;
    }
1295957
function create ($request, $match)
    {
        $extra = array(
                'user' => $request->user,
                'tenant' => $request->tenant
        );
        $form = new Geo_Form_Location(
                array_merge($request->REQUEST, $request->FILES), $extra);
        $cuser = $form->save();
        $request->user->setMessage(
                sprintf(__('the location %s has been created.'), 
                        (string) $cuser->name));
        
        User_Shortcuts_UpdateLeveFor($request->user, "jahanjoo_location_add");
        // Return response
        return new Pluf_HTTP_Response_Json($cuser);
    }
1078946
public function create($request, $match)
    {
        $receipt = Bank_Service::create($request, $request->REQUEST);
        return $receipt;
    }
157402
public function createAccountAction(Request $request)
    {
        $selfRegistration = $this->platformConfigHandler->getParameter('allow_self_registration');
        $casLogin = $request->getSession()->get('CAS_AUTHENTICATION_USER_ID');
        if (empty($casLogin) || !$selfRegistration) {
            return $this->redirectToRoute('claro_index');
        }

        return $this->casManager->createNewAccount($request, $casLogin);
    }
763654
public static function find($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $pag = new Pluf_Paginator(new User_Account());
        $sql = new Pluf_SQL('user_role_id=%s', array(
            $perm->id
        ));
        $pag->forced_where = $sql;
        $pag->list_filters = array(
            'is_active',
            'login',
            'first_name',
            'last_name',
            'email'
        );
        $pag->sort_order = array(
            'id',
            'ASC'
        );
        $search_fields = array(
            'login',
            'first_name',
            'last_name',
            'email'
        );
        $list_display = array(
            'login' => __('login'),
            'first_name' => __('first name'),
            'last_name' => __('last name'),
            'email' => __('email')
        );
        $sort_fields = array(
            'id',
            'login',
            'first_name',
            'last_name',
            'date_joined',
            'last_login'
        );
        $pag->model_view = 'join_role';
        $pag->configure($list_display, $search_fields, $sort_fields);
        $pag->setFromRequest($request);
        return $pag->render_object();
    }
82795
public static function delete($request, $match)
    {
        $group = Pluf_Shortcuts_GetObjectOr404('User_Group', $match['group_id']);
        $role = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $group->delAssoc($role);
        return $group;
    }
832207
public function putMap ($request, $match)
    {
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } else {
            $collectionId = $request->REQUEST['collectionId'];
        }
        // $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
        // $collectionId);
        if (isset($match['documentId'])) {
            $documentId = $match['documentId'];
        } else {
            $documentId = $request->REQUEST['documentId'];
        }
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        
        if ($document->collection != $collectionId) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $documentId .
                             ') does not exist in collection with id (' .
                             $collectionId . ')');
        }
        
        $this->putDocumentMap($document, $request->REQUEST);
        return new Pluf_HTTP_Response_Json($this->getDocumentMap($document));
    }
575307
public function createNewAccount(Request $request, $casLogin)
    {
        $user = new User();
        $form = $this->getRegistrationForm($user);
        $form->handleRequest($request);
        $session = $request->getSession();
        if ($form->isValid()) {
            $user = $this->userManager->createUser($user);

            $casUser = new CasUser($casLogin, $user);
            $this->om->persist($casUser);
            $this->om->flush();

            $msg = $this->translator->trans('account_created', [], 'platform');
            $session->getFlashBag()->add('success', $msg);

            if ($this->platformConfigHandler->getParameter('registration_mail_validation')) {
                $msg = $this->translator->trans('please_validate_your_account', [], 'platform');
                $session->getFlashBag()->add('success', $msg);
            }

            return $this->registrationManager->loginUser($user, $request);
        }

        return ['form' => $form->createView()];
    }
179048
public function delete($request, $match)
    {
        // تعیین داده‌ها
        $content = Pluf_Shortcuts_GetObjectOr404('CMS_Content', $match['modelId']);
        // بررسی دسترسی‌ها
        if (! CMS_Precondition::isAuthor($request)) {
            throw new Pluf_Exception_PermissionDenied('You are not an author');
        }
        if (! CMS_Precondition::isEditor($request) && $request->user->id !== $content->author_id) {
            throw new Pluf_Exception_PermissionDenied('You can not delete content created by another author');
        }
        return parent::deleteObject($request, $match, array(
            'model' => 'CMS_Content'
        ));
    }
67992
public static function count ($request, $match)
    {
        $userId = $request->user ? $request->user->id : 0;
        $sql = new Pluf_SQL('account_id=%s', array($userId));
        
        $message = new User_Message();
        $res = $message->getList(
                array(
                        'count' => true,
                        'filter' => $sql->gen()
                ));
        // Check permission
        return $res[0]['nb_items'];
    }
928672
public function create($request, $match)
    {
        // 1- upload & extract
        $key = 'spa-' . md5(microtime() . rand(0, 123456789));
        Pluf_Form_Field_File_moveToUploadFolder($request->FILES['file'], array(
            'file_name' => $key . '.zip',
            'upload_path' => Pluf::f('temp_folder', '/tmp'),
            'upload_path_create' => true,
            'upload_overwrite' => true
        ));
        $spa = Tenant_SpaService::installFromFile(Pluf::f('temp_folder', '/tmp') . '/' . $key . '.zip', true);
        return Tenant_Shortcuts_SpaManager($spa)->apply($spa, 'create');
    }
837142
public function createAction(Request $request)
    {
        $user = new User();
        $form = $this->createCreateForm($user);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            
            $user->setPassword($this->get('security.password_encoder')
                    ->encodePassword($user, $form['plainPassword']['password']->getData()));
            
            $em->persist($user);
            $em->flush();

            return $this->redirect($this->generateUrl('admin_user_show', array('id' => $user->getId())));
        }

        return $this->render('ChillMainBundle:User:new.html.twig', array(
            'entity' => $user,
            'form'   => $form->createView(),
        ));
    }