📜 ⬆️ ⬇️

“Service of free accounts” per day with Next Code

Let's start with the idea


For example, you went to the site in search of something. Access to content is limited. There are two options: register or search for the same content on another site. Chances are that this site will no longer be useful to you, and few people will want to litter your mail with spam, and just do some extra actions (registration, confirmation). In this case, you enter the address of the site in the service, and see if there are free accounts for this site. A free account can be any username and password that another user deemed unnecessary, and decided to share it with others in order to reduce their time.
The idea of ​​the site was born during the work day. The development took one working day. Motivation is the desire to prove that there are people who are ready to help other Internet users for free, and such projects can live.
The service was created using the Next Code all-in-one framework. Who cares how - welcome under cat.

Next Code


The framework consists of:
• NextJS - JS kernel, which includes ajax request processing, debugger, basic functions
• NextUIJS - visual components and extensions
• NextCSS - a set of CSS styles for quick layout
• XCode - PHP kernel, which includes working with the database, working with templates, debugger, application installer, parsers and much more.
The framework itself is developed for its own needs. Much has been done, but not all ideas are realized. Production version will be open-source. If it is interesting, I will write a separate article about the guts and all the features, of which there are not a few.

Development process


Configuring Xcode

To get started, select the necessary components for the display and operation of the site.
So we need:
1. Database Manager
2. MySQL driver
3. Template Manager
4. Smarty driver
5. Application Installer
6. Custom request handler
7. Plugin working with numbers
Configuration is done by setting up the ini files for each required component. In order for the component to be used during the work, the ini file with the settings must be put in the configuration folder.
For example, the ini file (plugins / numeric.ini) for the plugin for working with numbers looks like this:
[plugin]
name = numeric
class = plugin.numeric.default


Creating an application

The whole service is a single application - freeacc.
The application includes:
1. class xcFreeAcc_Application (the system name is application.freeacc)
2. configuration file
3. essence freeacc_account for storing accounts
4. essence freeacc_site - to store sites
5. freeacc_verify entity - for storing account accessibility ratings
6. list of reserved requests
7. page template
The application is stored in the repository at application / freeacc /
For the system to determine the application, you must install it.

 xc("call.application.freeacc::__install"); 

')
The __install function performs the following actions:

 public static function __install() { $app_id = xc::query( "api.application.install", xc::query( "setting", "name", "application", __class__ ), xc::query( "setting", "caption", "application", __class__ ) ); xc::query( "api.application.registerComponents", xc::query( "setting", "name", "application", __class__ ), $app_id ); } 


The first line calls the application installer API, passing the name and title of the application (values ​​are taken from the configuration file).
The second line creates entities and reserves requests for the application.
The app is ready to go!

Creating templates

Based on the principles of MVC, an application requires a tpl file with a layout, and a php file as a controller. The model is the application class.
Tpl file code
 <div class="xc-fullpage-layout"> <div class="xc-layout-header"> <div class="xc-layout-frame"> <div class="xc-grid"> <div class="block logo xc-column"><a href="/"><img src="{$MEDIAPATH}/logo.png" /></a></div> <div class="block motto xc-column"><span class="delimiter">|</span> <span class="motto">  </span></div> </div> <div class="block description"> <span>     ,  ,    </span> </div> </div> </div> <div class="xc-layout-content xc-center"> <div class="xc-layout-frame"> {if $self} {$self} {else} {$likes} {/if} <form title=" " id="addForm" action="freeacc/forms/add_form" class="ui-component-form" data-valid-timeout="3000" data-valid-message=", ..." data-valid-area=">footer.ui-element-validation"> <fieldset class="fields"> <div class="header"> <h2>  :</h2> </div> <ul class="xc-grid"> <li class="item ui-component xc-column"> <div class="xc-grid"> <div class="field xc-column"><input name="url" title="" placeholder="  ..." class="ui-component-edit" pattern="site" type="text" required /></div> <div class="field xc-column"><input name="login" title="" placeholder=" ..." class="ui-component-edit" type="text" required /></div> <div class="field xc-column"><input name="password" title="" placeholder=" ..." class="ui-component-edit" type="text" required /></div> </div> </li> <li class="item control xc-column"> <button class="ui-component-button" type="submit"></button> </li> </ul> </fieldset> <footer class="ui-element-validation"> </footer> </form> <form title=" " id="requestForm" data-callback-function="postRequest" data-action="none" class="ui-component-form" data-valid-timeout="3000" data-valid-message=", ..." data-valid-area=">footer.ui-element-validation"> <fieldset class="fields"> <div class="header"> <h2>  : *</h2> </div> <ul class="xc-grid"> <li class="item ui-component xc-column"> <div class="field"><input name="url" title="" placeholder="  ..." class="ui-component-edit" pattern="site" type="text" required /></div> </li> <li class="item control xc-column"> <button class="ui-component-button" type="submit"></button> </li> </ul> </fieldset> <div class="description"> *   .    .         ! </div> <footer class="ui-element-validation"> </footer> </form> {if !$self} <div class="block table xc-full"> <div class="site"> <span>  <b>{$accounts->asFormat(0,"."," ")}</b> {$accounts->getDeclension(array("","",""))}  <b>{$sites->asFormat(0,"."," ")}</b> {$sites->getDeclension(array("","",""))}</span> </div> <div class="table"> <div class="xc-grid xc-full" data-account="{$item.id}"> <div class="header"> </div> {foreach from=$favorites item=item} <div class="xc-item"><a href="/{$item.url}/">{$item.url}</a> ({$item.cnt})</div> {/foreach} </div> </div> </div> {/if} </div> </div> <div class="xc-layout-footer"> <div class="xc-layout-frame"> </div> </div> </div> <div id="alertModal" data-popup-modal="true" class="ui-popup"> </div> <div id="alertPopup" class="ui-popup popup"> </div> <div id="alertMessage" data-popup-modal="true" class="ui-popup message"> </div> </body> 

The controller created to process this template is as follows:

 $self = ""; xc("tpl likes=freeacc/blocks/likes comments=freeacc/blocks/comments :fetch"); if (isset(xc("tpl")->variable("this")->extra['site'])) { xc("tpl")->assign("site",xc("tpl")->variable("this")->extra['site']); $accounts = xc("call.application.freeacc::getAccounts",xc("tpl")->variable("this")->extra['site']); $self = xc("tpl freeacc/blocks/accounts")->apply($accounts); } else { xc("tpl")->assign("accounts",xc("plugin.numeric",true)->setData(xc("db freeacc_account")->fields("COUNT(*) as cnt")->cnt)); xc("tpl")->assign("sites",xc("plugin.numeric",true)->setData(xc("db freeacc_site")->fields("COUNT(*) as cnt")->cnt)); xc("tpl")->assign("favorites",xc("db freeacc_account:group(url):order(cnt down):limit(0,20)")->fields("url,COUNT(#id#) as cnt")); } xc("tpl")->assign("self", $self); 


I think for any web programmer, the "view" template will not cause any difficulties when reading.
The controller performs the following actions:
• Creates variables likes and comments to display likes and comments Vkontakte
• Checks the presence of the site in the request (if there is no site, then we are on the main page)
• Places the desired site in the variable site for quick access within the template
• Calls the function of the application to get the accounts of the desired site
• Processes a template with an account table
• Creates a variable accounts with the number of accounts in the database
• Creates a variable sites with the number of sites in the database
• Creates a variable of favorites with 20 sites to which most accounts
The add form handler looks like this:

 $id = xc("call.application.freeacc::addAccount",$_GET['fields']); if ($id) { $GLOBALS['_RESULT']["result"] = ""; $GLOBALS['_RESULT']["debug"]["info"] = " "; $GLOBALS['_RESULT']["debug"]["type"] = "success"; } else { $GLOBALS['_RESULT']["result"] = ""; $GLOBALS['_RESULT']["debug"]["info"] = " "; $GLOBALS['_RESULT']["debug"]["type"] = "fail"; } 


Render the template.
 $(function() { $(".block.table a.verify").live("click",function() { var obj = $(this); $$.database.get("ajax").onReadyState(function(result) { obj.parent().empty().text(" "); }); $$.database.get("ajax").send({"mode": "ajax", "type": "API", "api": "freeacc.account.verify", "parameters":[$(this).parents("div[data-account]").attr("data-account")]}); }); $(".block.table a.unverify").live("click",function() { var obj = $(this); $$.database.get("ajax").onReadyState(function(result) { obj.parent().empty().text(" "); }); $$.database.get("ajax").send({"mode": "ajax", "type": "API", "api": "freeacc.account.unverify", "parameters":[$(this).parents("div[data-account]").attr("data-account")]}); }); }); function postRequest() { $$.fn.redirect("/"+$$("#requestForm [name='url']").val()+"/"); } 


Subject hub does not allow me to specify a link to the service, because it will be considered as advertising. There is no karma for transfer to “I am promoting”. I can indicate the link in comments or in a LAN. Although a wise reader will easily add ".ru";)

PS my first post on Habré, I hope for understanding.
PPS is ready to add something that is not added about the service or technology.
PPPS with the Russian language problem, so I think that on the site, that the article has a lot of errors. I will be glad to fix it!

UPD: thanks to those who have treated with understanding! Nobody asks about technology, maybe I didn’t say that the whole dynamics of the system is not clear

Source: https://habr.com/ru/post/142996/


All Articles