Javascript-форум (https://javascript.ru/forum/)
-   Node.JS (https://javascript.ru/forum/node-js-io-js/)
-   -   Верификация пользователя с помощью e-mail (https://javascript.ru/forum/node-js-io-js/69597-verifikaciya-polzovatelya-s-pomoshhyu-e-mail.html)

odrovunos 05.07.2017 13:12

Верификация пользователя с помощью e-mail
 
Можете помочь? Я прошел краткий курс javaScript, не могу справиться. У меня задача написать код верификации пользователя через e-mail, в форме нужно ввести имя, фамилию, номер телефона, e-mail, после верного заполнения генерируется ссылка пройдя по которой происходит верификация пользователя.
Нашел в интернете части кода но, не могу их увязать.

<div><style type="text/css">
#ok {
background-color: #96070A;
display: none;
position: fixed;
z-index: 99999;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#parent_popup {
background-color: #96070A;
display: none;
position: fixed;
z-index: 99999;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#popup {
background: #ECE9E4;
width: 300px;
margin: 20% auto;
padding: 1px 1px 1px 1px;
border: 10px solid #ddd;
position: relative;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;

}

#btn{
background: rgb(212,75,56); /* фон кнопки */ color:#FFFFFF;
width: 150px;
padding: 10px 50px; /* отступ от текста */
//margin-left:79px;
//margin-right:0px;
margin-top:10px;
text-decoration: Bodoni MT;
font-size:12px !important;
border-radius: 3px;
}
#data
{
text-align: center;
margin: 1% auto;
width: 150px;
hight: 30px;
position: relative; top: 5px; left: 0%;
}
#btn:hover {background: #8BCD28; color:#000000;/* фон и цвет кнопки */} /* при наведении курсора мышки */
border-radius: 50%;}

}

input[type="text"], input[type="email"] {
width: 100px;
}
.invalid {
background: red;
}

</style>

</div>
<div id="parent_popup">
<div id="popup">
<form id="test">
<div>
<input type="text" title="имя"></input>
<input type="text" title="фамилия"></input>
<input type="text" title="мобильный номер"></input>
<input type="email" title="email"></input>
<span id="required"></span><br>
<input type="submit" >
</form>
</div>
<div id="ok">
</div>
</div>
<script>
window.onload = function() {

var form = document.forms[0],
fields = form.querySelectorAll('input[type="text"], input[type="email"]'),
msg = document.getElementById('required'),
regExp = [/^[А-Яа-яЁё]+$/, /.+@.+\..+/i, /^[А-Яа-яЁё\W\s\d]+$/, /^[А-Яа-яЁё\W\s\d]+$/];

form.onsubmit = function(event) {
var valid = true, cnt = 0;

event.preventDefault();

Array.prototype.forEach.call(fields, function(input) {
input.classList.remove('invalid');
if(!input.value.length) {
cnt++;
}
})

if(cnt == fields.length) {
Array.prototype.forEach.call(fields, function(input) {
input.classList.add('invalid');
})
msg.innerHTML = 'Заполните обязательные поля!';
return;
}

for (var i = 0, l = fields.length; i &lt; l; i++) {
fields[i].classList.remove('invalid');
if(!fields[i].value.match(regExp[i])) {
fields[i].classList.add('invalid');
msg.innerHTML = 'Неверно введено поле ' + fields[i].title + '!';
valid = false;
break;
}
}

if (valid) {
form.submit();
}

}
}
function fnLink() {
var strLink;

strLink = "http://www.sql.ru";

window.location.href = strLink
}
/* SmtpJS.com */
Email = { send: function (a, b, c, d, e, f, g) { var h = Math.floor(1e6 * Math.random() + 1), i = "https://smtpjs.com/smtp.aspx?"; i += "From=" + a, i += "&to=" + b, i += "&Subject=" + encodeURIComponent(c), i += "&Body=" + encodeURIComponent(d), void 0 == e.token ? (i += "&Host=" + e, i += "&Username=" + f, i += "&Password=" + g, i += "&Action=Send") : (i += "&SecureToken=" + e.token, i += "&Action=SendFromStored"), i += "&cachebuster=" + h, Email.ajax(i) }, sendWithAttachment: function (a, b, c, d, e, f, g, h) { var i = Math.floor(1e6 * Math.random() + 1), j = "https://smtpjs.com/smtp.aspx?"; j += "From=" + a, j += "&to=" + b, j += "&Subject=" + encodeURIComponent(c), j += "&Body=" + encodeURIComponent(d), j += "&Attachment=" + encodeURIComponent(h), void 0 == e.token ? (j += "&Host=" + e, j += "&Username=" + f, j += "&Password=" + g, j += "&Action=Send") : (j += "&SecureToken=" + e.token, j += "&Action=SendFromStored"), j += "&cachebuster=" + i, Email.ajax(j) }, ajax: function (a) { var b = Email.createCORSRequest("GET", a); b.onload = function () { var a = b.responseText; console.log(a) }, b.send() }, createCORSRequest: function (a, b) { var c = new XMLHttpRequest; return "withCredentials" in c ? c.open(a, b, !0) : "undefined" != typeof XDomainRequest ? (c = new XDomainRequest, c.open(a, b)) : c = null, c } };
</script>

odrovunos 17.07.2017 09:15

Можете помочь увязать блоки для отправки генерируемого кода для активации на сайте на указанный имейл пользователя.
Код:

<script language="javascript" type="text/javascript">
var numbers = []
function getRandomArbitrary(0, 100 000) {
  return Math.random() * (100 000 - 0) + 0;
}
numbers.push(getElementById(getRandomArbitrary))

function SendMail(){ 
    try 
    { 
        // create a session and log on -- username and password in profile   
        var refMsg = WScript.CreateObject("CDO.Message"); 
        var refConf = WScript.CreateObject("CDO.Configuration"); 

        // Setting configuration params 
        with(refConf.Fields) 
        { 
            Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.ru"; 
            Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;
            Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1; 
            Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "***@mail.ru"; 
            Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Тут типо пароль";
        } 
        refConf.Fields.Update(); 

        with(refMsg) 
        { 
            Configuration = refConf; 
            To      = getElementByID(email); 
            From    = "odrovunos@gmail.com"; 
            Subject  = "код верификации"; 
            TextBody = "Укажите пожалуйста на данной странице www.page.com код верификации (getElementByID(getRandomArbitrary))";
        }
        refMsg.Send(); 
    }   
    catch(e) 
    { 
    WScript.Echo("SendMail error !!! : " + e.description); 
    WScript.Quit(1); 
    }
}

</script>

 <form action="handler.php">
 <td align="center"><h3>Форма для заполнения</h3>
<form method="post" action="submit.php">
<p><input type="text" size="40" placeholder="Ваше имя" name="user"></p>
<p><input type="text" size="40" placeholder="Телефон" name="tel"></p>
<p><input id ="email"type="text" size="40" placeholder="E-mail" name="email"></p>
<p><input type="submit" value="Получить"></p>                   
</form>

<input type="button" value="Отправить" name="rbtest" onClick="SendMail()">



Часовой пояс GMT +3, время: 05:54.