Commit 94c38fe1 authored by 神楽坂玲奈's avatar 神楽坂玲奈

login

parent d01d0db1
login = (username, password)->
$('#username').html username
$('#login').hide()
$('#userinfo').show()
$('#need_login').hide()
$('#join').show()
$('#logout').click ->
$.cookie('username', '')
$.cookie('password', '')
window.location.reload()
$('#login').submit ->
$.cookie('username', @username.value)
$.cookie('password', @password.value)
login($.cookie('username'), $.cookie('password'))
false
matched = window.location.href.match /\/(?:(.*?)(?::(.*?))?@)?([\d\.]+)\:(\d+)(?:\/(.*))?/ matched = window.location.href.match /\/(?:(.*?)(?::(.*?))?@)?([\d\.]+)\:(\d+)(?:\/(.*))?/
if matched == null if matched == null
alert "解析房间信息失败" alert "解析房间信息失败"
...@@ -31,5 +48,12 @@ $('#server_ip').html room.server.ip ...@@ -31,5 +48,12 @@ $('#server_ip').html room.server.ip
$('#server_port').html room.server.port $('#server_port').html room.server.port
$('#server_auth').html room.server.auth $('#server_auth').html room.server.auth
if room.server.auth and !($.cookie('username') && $.cookie('password'))
$('#join').hide()
$('#need_login').show()
if $.cookie('username') && $.cookie('password')
login($.cookie('username'), $.cookie('password'))
$('#join').click -> $('#join').click ->
mycard.join room.server.ip,room.server.port,mycard.room_name(room.name, room.password) mycard.join room.server.ip,room.server.port,mycard.room_name(room.name, room.password), $.cookie('username'), ($.cookie('password') if room.server.auth)
\ No newline at end of file \ No newline at end of file
// Generated by CoffeeScript 1.4.0 // Generated by CoffeeScript 1.4.0
(function() { (function() {
var matched, room, url; var login, matched, room, url;
login = function(username, password) {
$('#username').html(username);
$('#login').hide();
$('#userinfo').show();
$('#need_login').hide();
return $('#join').show();
};
$('#logout').click(function() {
$.cookie('username', '');
$.cookie('password', '');
return window.location.reload();
});
$('#login').submit(function() {
$.cookie('username', this.username.value);
$.cookie('password', this.password.value);
login($.cookie('username'), $.cookie('password'));
return false;
});
matched = window.location.href.match(/\/(?:(.*?)(?::(.*?))?@)?([\d\.]+)\:(\d+)(?:\/(.*))?/); matched = window.location.href.match(/\/(?:(.*?)(?::(.*?))?@)?([\d\.]+)\:(\d+)(?:\/(.*))?/);
...@@ -42,8 +63,17 @@ ...@@ -42,8 +63,17 @@
$('#server_auth').html(room.server.auth); $('#server_auth').html(room.server.auth);
if (room.server.auth && !($.cookie('username') && $.cookie('password'))) {
$('#join').hide();
$('#need_login').show();
}
if ($.cookie('username') && $.cookie('password')) {
login($.cookie('username'), $.cookie('password'));
}
$('#join').click(function() { $('#join').click(function() {
return mycard.join(room.server.ip, room.server.port, mycard.room_name(room.name, room.password)); return mycard.join(room.server.ip, room.server.port, mycard.room_name(room.name, room.password), $.cookie('username'), (room.server.auth ? $.cookie('password') : void 0));
}); });
}).call(this); }).call(this);
This diff is collapsed.
/*! /*!
* jQuery Cookie Plugin v1.3.0 * jQuery Cookie Plugin v1.3.1
* https://github.com/carhartl/jquery-cookie * https://github.com/carhartl/jquery-cookie
* *
* Copyright 2013 Klaus Hartl * Copyright 2013 Klaus Hartl
* Released under the MIT license * Released under the MIT license
*/ */
(function ($, document, undefined) { (function (factory) {
if (typeof define === 'function' && define.amd && define.amd.jQuery) {
// AMD. Register as anonymous module.
define(['jquery'], factory);
} else {
// Browser globals.
factory(jQuery);
}
}(function ($) {
var pluses = /\+/g; var pluses = /\+/g;
...@@ -14,15 +22,17 @@ ...@@ -14,15 +22,17 @@
} }
function decoded(s) { function decoded(s) {
return unRfc2068(decodeURIComponent(s.replace(pluses, ' '))); return decodeURIComponent(s.replace(pluses, ' '));
} }
function unRfc2068(value) { function converted(s) {
if (value.indexOf('"') === 0) { if (s.indexOf('"') === 0) {
// This is a quoted cookie as according to RFC2068, unescape // This is a quoted cookie as according to RFC2068, unescape
value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
} }
return value; try {
return config.json ? JSON.parse(s) : s;
} catch(er) {}
} }
var config = $.cookie = function (key, value, options) { var config = $.cookie = function (key, value, options) {
...@@ -31,10 +41,6 @@ ...@@ -31,10 +41,6 @@
if (value !== undefined) { if (value !== undefined) {
options = $.extend({}, config.defaults, options); options = $.extend({}, config.defaults, options);
if (value === null) {
options.expires = -1;
}
if (typeof options.expires === 'number') { if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date(); var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days); t.setDate(t.getDate() + days);
...@@ -54,23 +60,19 @@ ...@@ -54,23 +60,19 @@
// read // read
var decode = config.raw ? raw : decoded; var decode = config.raw ? raw : decoded;
var cookies = document.cookie.split('; '); var cookies = document.cookie.split('; ');
var result = key ? null : {}; var result = key ? undefined : {};
for (var i = 0, l = cookies.length; i < l; i++) { for (var i = 0, l = cookies.length; i < l; i++) {
var parts = cookies[i].split('='); var parts = cookies[i].split('=');
var name = decode(parts.shift()); var name = decode(parts.shift());
var cookie = decode(parts.join('=')); var cookie = decode(parts.join('='));
if (config.json) {
cookie = JSON.parse(cookie);
}
if (key && key === name) { if (key && key === name) {
result = cookie; result = converted(cookie);
break; break;
} }
if (!key) { if (!key) {
result[name] = cookie; result[name] = converted(cookie);
} }
} }
...@@ -80,11 +82,11 @@ ...@@ -80,11 +82,11 @@
config.defaults = {}; config.defaults = {};
$.removeCookie = function (key, options) { $.removeCookie = function (key, options) {
if ($.cookie(key) !== null) { if ($.cookie(key) !== undefined) {
$.cookie(key, null, options); $.cookie(key, '', $.extend(options, { expires: -1 }));
return true; return true;
} }
return false; return false;
}; };
})(jQuery, document); }));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment