enricostara/telegram.link

View on GitHub
doc/api/auth.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>

<html>
<head>
  <title>auth.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="../docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>auth.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <pre><code>telegram.link
Copyright <span class="hljs-number">2014</span> Enrico Stara <span class="hljs-string">'enrico.stara@gmail.com'</span>
Released under the MIT License
http:<span class="hljs-comment">//telegram.link</span>
</code></pre>
            </div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>Dependencies:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre><span class="hljs-keyword">var</span> api = <span class="hljs-built_in">require</span>(<span class="hljs-string">'../api'</span>);
<span class="hljs-keyword">var</span> utility = <span class="hljs-built_in">require</span>(<span class="hljs-string">'../utility'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <hr>

            </div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <p>This module wraps API methods required to the user to gain the authorization.</p>

            </div>
            
        </li>
        
        
        <li id="section-5">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-5">&#182;</a>
              </div>
              <p>See <a href="https://core.telegram.org/api/auth">User Authorization</a>
and <a href="https://core.telegram.org/methods#registration-authorization">Api Methods</a></p>

            </div>
            
        </li>
        
        
        <li id="section-6">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-6">&#182;</a>
              </div>
              <p>Access only via Client object and <code>auth</code> instance property</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Auth</span>(<span class="hljs-params">client</span>) </span>{
    <span class="hljs-keyword">this</span>.client = client;
}</pre></div></div>
            
        </li>
        
        
        <li id="section-7">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-7">&#182;</a>
              </div>
              <hr>

            </div>
            
        </li>
        
        
        <li id="section-8">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-8">&#182;</a>
              </div>
              <p><strong>Event: </strong><code>&#39;method name&#39;</code></p>

            </div>
            
        </li>
        
        
        <li id="section-9">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-9">&#182;</a>
              </div>
              <p>Each of the following methods emits an event with the same name when done, an <code>error</code> event otherwise.</p>

            </div>
            
        </li>
        
        
        <li id="section-10">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-10">&#182;</a>
              </div>
              <hr>
<p>auth.<strong>sendCode(phone_number, sms_type, lang_code, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-11">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-11">&#182;</a>
              </div>
              <p>Send a text message with the confirmation code required for registration to the given phone number.</p>

            </div>
            
        </li>
        
        
        <li id="section-12">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-12">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/auth.sendCode">Click here for more details</a></p>

            </div>
            
        </li>
        
        
        <li id="section-13">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-13">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Auth.prototype.sendCode = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phone_number, sms_type, lang_code, callback</span>) </span>{
    <span class="hljs-keyword">if</span> (callback) {
        <span class="hljs-keyword">this</span>.client.once(<span class="hljs-string">'sendCode'</span>, callback);
    }
    <span class="hljs-keyword">var</span> props = {
        phone_number: phone_number,
        sms_type: sms_type,
        api_id: <span class="hljs-keyword">this</span>.client._app.id,
        api_hash: <span class="hljs-keyword">this</span>.client._app.hash,
        lang_code: lang_code
    };
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.client.isReady(<span class="hljs-literal">true</span>)) {
        <span class="hljs-keyword">try</span> {
            api.service.auth.sendCode({
                props: props,
                channel: <span class="hljs-keyword">this</span>.client._channel,
                callback: utility.createEventEmitterCallback(<span class="hljs-string">'sendCode'</span>, <span class="hljs-keyword">this</span>.client)
            });
        } <span class="hljs-keyword">catch</span> (err) {
            <span class="hljs-keyword">this</span>.client.emit(<span class="hljs-string">'error'</span>, err);
        }
    }
};</pre></div></div>
            
        </li>
        
        
        <li id="section-14">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-14">&#182;</a>
              </div>
              <hr>
<p>auth.<strong>sendCall(phone_number, phone_code_hash, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-15">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-15">&#182;</a>
              </div>
              <p>Return a Promise to make a voice call to the passed phone number.
A robot will repeat the confirmation code from a previously sent SMS message.</p>

            </div>
            
        </li>
        
        
        <li id="section-16">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-16">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/auth.sendCall">Click here for more details</a></p>

            </div>
            
        </li>
        
        
        <li id="section-17">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-17">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Auth.prototype.sendCall = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phone_number, phone_code_hash, callback</span>) </span>{
    <span class="hljs-keyword">return</span> utility.callService(api.service.auth.sendCall, <span class="hljs-keyword">this</span>.client, <span class="hljs-keyword">this</span>.client._channel, callback, <span class="hljs-built_in">arguments</span>);
};</pre></div></div>
            
        </li>
        
        
        <li id="section-18">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-18">&#182;</a>
              </div>
              <hr>
<p>auth.<strong>signIn(phone_number, phone_code_hash, phone_code, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-19">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-19">&#182;</a>
              </div>
              <p>Return a Promise to sign in a user with a validated phone number.</p>

            </div>
            
        </li>
        
        
        <li id="section-20">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-20">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/auth.signIn">Click here for more details</a></p>

            </div>
            
        </li>
        
        
        <li id="section-21">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-21">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Auth.prototype.signIn = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phone_number, phone_code_hash, phone_code, callback</span>) </span>{
    <span class="hljs-keyword">return</span> utility.callService(api.service.auth.signIn, <span class="hljs-keyword">this</span>.client, <span class="hljs-keyword">this</span>.client._channel, callback, <span class="hljs-built_in">arguments</span>);
};</pre></div></div>
            
        </li>
        
        
        <li id="section-22">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-22">&#182;</a>
              </div>
              <hr>
<p>auth.<strong>signUp(phone_number, phone_code_hash, phone_code, first_name, last_name, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-23">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-23">&#182;</a>
              </div>
              <p>Return a Promise to register a validated phone number in the system.</p>

            </div>
            
        </li>
        
        
        <li id="section-24">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-24">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/auth.signUp">Click here for more details</a></p>

            </div>
            
        </li>
        
        
        <li id="section-25">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-25">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Auth.prototype.signUp = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phone_number, phone_code_hash, phone_code, first_name, last_name, callback</span>) </span>{
    <span class="hljs-keyword">return</span> utility.callService(api.service.auth.signUp, <span class="hljs-keyword">this</span>.client, <span class="hljs-keyword">this</span>.client._channel, callback, <span class="hljs-built_in">arguments</span>);
};</pre></div></div>
            
        </li>
        
        
        <li id="section-26">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-26">&#182;</a>
              </div>
              <hr>
<p>auth.<strong>checkPhone(phone_number, [callback])</strong></p>

            </div>
            
        </li>
        
        
        <li id="section-27">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-27">&#182;</a>
              </div>
              <p>Return a Promise to get the information on whether the passed phone number was registered.</p>

            </div>
            
        </li>
        
        
        <li id="section-28">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-28">&#182;</a>
              </div>
              <p><a href="https://core.telegram.org/method/auth.checkPhone">Click here for more details</a></p>

            </div>
            
        </li>
        
        
        <li id="section-29">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-29">&#182;</a>
              </div>
              <p>The code:</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>Auth.prototype.checkPhone = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">phone_number, callback</span>) </span>{
    <span class="hljs-keyword">return</span> utility.callService(api.service.auth.checkPhone, <span class="hljs-keyword">this</span>.client, <span class="hljs-keyword">this</span>.client._channel, callback, <span class="hljs-built_in">arguments</span>);
};</pre></div></div>
            
        </li>
        
        
        <li id="section-30">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-30">&#182;</a>
              </div>
              <p>Export the class.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">module</span>.exports = exports = Auth;</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>