function LoginUser() { var login = $('#login')[0].value; var password = $('#password')[0].value; if(login!='' && password!='') { $('#keyBtn')[0].onclick = null; $('#keyBtn')[0].src = '/images/progress_active.gif'; $.post('/ajax/login', { login:login, password: password }, function(results) { autorise(results); }, 'json' ); } } function setAutorisation(code, uni, sid) { var exdate = new Date(); exdate.setYear(2016); document.cookie="uni="+uni+"; path=/; expires=" + exdate.toGMTString(); document.cookie="code="+code+"; path=/; expires=" + exdate.toGMTString(); document.cookie="sid="+sid+"; path=/; expires=" + exdate.toGMTString(); window.location.reload(); } function authInfo(response) { if (response.session) { getInitData(response.session.sig); } else { } } function getInitData(sig) { var code = 'return {'; code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname, sex, bdate, city, country, photo, photo_medium, photo_big"})[0]'; code += ', user: API.getUserInfoEx({api_id: 2373677, sig: "'+sig+'", v: "2.0"})' code += '};'; VK.Api.call('execute', {'code': code}, onGetInitData); } function onGetInitData(data) { if (data.response) { var id = 'VK_'+data.response.me.uid; var firstName = data.response.me.first_name; var nickName = data.response.me.nickname; var lastName = data.response.me.last_name; var avatar = data.response.me.photo_big; var sex = data.response.me.sex-1; var birsday = [0,0,0]; if (data.response.me.bdate > '') birsday = data.response.me.bdate.split("."); $.post('/ajax/oauth', {id: id, firstName: firstName, nickName: nickName, lastName: lastName, birsday: birsday[2]+'-'+birsday[1]+'-'+birsday[0], avatar: avatar, sex: sex, ref: ''}, function(data){ VK.Auth.logout(autorise(data)); }, 'json'); } } function autorise(data) { if (data.result[0] == 'success') { setAutorisation(data.result[1], data.result[2], data.result[3]); } else { switch (data.errors[0]) { case 0: $('#notifycontent').dialog('close'); $('#notifycontent').html('

'+ ''+ ''); $('#notifycontent').dialog("option", "title", "").dialog('open'); break; case 1: $('#notifycontent').dialog('close'); $('#notifycontent').html(' '+data.errors[1]+'

'+ ''); $('#notifycontent').dialog("option", "title", "").dialog('open'); break; default: $('#passremind').show(); $('#messages').html('
'); break; } $('#keyBtn').click(function() { LoginUser() }); $('#keyBtn')[0].src = '/images/key.png'; } } $('#no').live('click', function(){ $('#notifycontent').dialog('close'); }); $('#reanimprofile').live('click', function(){ $.post('/ajax/reanimprofile', {uid: $(this).attr('uid')}, function(data){ $('#messages').html('
'+data+'
'); $('#notifycontent').dialog('close'); }); }); $(function(){ $('#loginform').submit(function(){ $('#keyBtn').click(); return false; }); FB.init({ appId:128878097191033, cookie:false, status:false, xfbml:true }); FB.Event.subscribe('auth.login', function(response) { FB.api('/me', function(user) { if(user.id > 0) { var id = 'FB_'+user.id; var firstName = user.first_name; var nickName = user.last_name; var lastName = user.middle_name; var avatar = 'http://graph.facebook.com/'+user.id+'/picture?type=large'; var sex = 0; if (user.gender == 'male') sex = 1; $.post('/ajax/oauth', {id: id, firstName: firstName, nickName: nickName, lastName: lastName, avatar: avatar, sex: sex, ref: ''}, function(data){ FB.logout(autorise(data)); }, 'json'); } else FB.logout(); }); }); // start Авторизация ВКонтакте VK.init({ apiId: 2373677, nameTransportPath: 'http://durov.at/xd_receiver.html', vk: 1 }); VK.Observer.subscribe('auth.login', authInfo); VK.UI.button('login_button'); // end Авторизация ВКонтакте });