mirror of https://github.com/calzoneman/sync.git
More work
This commit is contained in:
parent
74203ad223
commit
c8df4b036c
52
api.js
52
api.js
|
@ -28,6 +28,8 @@ var jsonHandlers = {
|
|||
"changepass" : handlePasswordChange,
|
||||
"resetpass" : handlePasswordReset,
|
||||
"recoverpw" : handlePasswordRecover,
|
||||
"setprofile" : handleProfileChange,
|
||||
"getprofile" : handleProfileGet,
|
||||
"setemail" : handleEmailChange,
|
||||
"globalbans" : handleGlobalBans,
|
||||
"admreports" : handleAdmReports,
|
||||
|
@ -236,8 +238,9 @@ function handlePasswordReset(params, req, res) {
|
|||
var email = unescape(params.email || "");
|
||||
var ip = req.socket.address().address;
|
||||
|
||||
var hash = false;
|
||||
try {
|
||||
Database.generatePasswordReset(ip, name, email);
|
||||
hash = Database.generatePasswordReset(ip, name, email);
|
||||
}
|
||||
catch(e) {
|
||||
sendJSON(res, {
|
||||
|
@ -247,6 +250,7 @@ function handlePasswordReset(params, req, res) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
sendJSON(res, {
|
||||
success: true
|
||||
});
|
||||
|
@ -275,6 +279,52 @@ function handlePasswordRecover(params, req, res) {
|
|||
|
||||
}
|
||||
|
||||
function handleProfileGet(params, req, res) {
|
||||
var name = params.name || "";
|
||||
|
||||
try {
|
||||
var prof = Database.getProfile(name);
|
||||
sendJSON(res, {
|
||||
success: true,
|
||||
profile_image: prof.profile_image,
|
||||
profile_text: prof.profile_text
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
sendJSON(res, {
|
||||
success: false,
|
||||
error: e
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleProfileChange(params, req, res) {
|
||||
var name = params.name || "";
|
||||
var pw = params.pw || "";
|
||||
var session = params.session || "";
|
||||
var img = unescape(params.profile_image || "");
|
||||
var text = unescape(params.profile_text || "");
|
||||
|
||||
var row = Auth.login(name, pw, session);
|
||||
if(!row) {
|
||||
sendJSON(res, {
|
||||
success: false,
|
||||
error: "Invalid login"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var result = Database.setProfile(name, {
|
||||
image: img,
|
||||
text: text
|
||||
});
|
||||
|
||||
sendJSON(res, {
|
||||
success: result,
|
||||
error: result ? "" : "Internal error. Contact an administrator"
|
||||
});
|
||||
}
|
||||
|
||||
function handleEmailChange(params, req, res) {
|
||||
var name = params.name || "";
|
||||
var pw = params.pw || "";
|
||||
|
|
31
database.js
31
database.js
|
@ -558,6 +558,34 @@ function channelUnbanName(chan, name) {
|
|||
|
||||
/* REGION Users */
|
||||
|
||||
function getProfile(name) {
|
||||
var db = getConnection();
|
||||
if(!db) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var query = createQuery(
|
||||
"SELECT profile_image,profile_text FROM registrations WHERE uname=?",
|
||||
[name]
|
||||
);
|
||||
|
||||
var results = db.querySync(query);
|
||||
if(!results) {
|
||||
Logger.errlog.log("! Failed to retrieve user profile");
|
||||
throw "Database failure. Contact an administrator.";
|
||||
}
|
||||
|
||||
var rows = results.fetchAllSync();
|
||||
if(rows.length == 0) {
|
||||
throw "User not found";
|
||||
}
|
||||
|
||||
return {
|
||||
profile_image: rows[0].profile_image,
|
||||
profile_text: rows[0].profile_text
|
||||
};
|
||||
}
|
||||
|
||||
function setProfile(name, data) {
|
||||
var db = getConnection();
|
||||
if(!db) {
|
||||
|
@ -637,7 +665,7 @@ function generatePasswordReset(ip, name, email) {
|
|||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return hash;
|
||||
}
|
||||
|
||||
function recoverPassword(hash) {
|
||||
|
@ -723,6 +751,7 @@ exports.channelBan = channelBan;
|
|||
exports.channelUnbanIP = channelUnbanIP;
|
||||
exports.channelUnbanName = channelUnbanName;
|
||||
exports.setProfile = setProfile;
|
||||
exports.getProfile = getProfile;
|
||||
exports.setUserEmail = setUserEmail;
|
||||
exports.generatePasswordReset = generatePasswordReset;
|
||||
exports.recoverPassword = recoverPassword;
|
||||
|
|
|
@ -182,6 +182,28 @@
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="span7" id="profilepane" style="display: none">
|
||||
<h3>Profile</h3>
|
||||
<form class="form-horizontal" action="javascript:void(0)">
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="profileimg">Image</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="profileimg">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="profiletext">Text</label>
|
||||
<div class="controls">
|
||||
<textarea rows="10" id="profiletext"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<button class="btn btn-primary" id="profilesave">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- /container -->
|
||||
<div class="push"></div>
|
||||
|
|
|
@ -42,6 +42,22 @@ $("#register").click(makeTabCallback("#register", "#registerpane"));
|
|||
$("#pwchange").click(makeTabCallback("#pwchange", "#changepwpane"));
|
||||
$("#pwreset").click(makeTabCallback("#pwreset", "#pwresetpane"));
|
||||
$("#email").click(makeTabCallback("#email", "#changeemailpane"));
|
||||
$("#profile").click(makeTabCallback("#profile", "#profilepane"));
|
||||
$("#profile").click(function() {
|
||||
if(uname != "") {
|
||||
$.getJSON(api + "getprofile?name=" + uname + "&callback=?", function(data) {
|
||||
if(data.success) {
|
||||
$("#profiletext").val(data.profile_text);
|
||||
$("#profileimg").val(data.profile_image);
|
||||
}
|
||||
else {
|
||||
$("<div/>").addClass("alert alert-error")
|
||||
.text("Failed to retrieve profile: " + data.error)
|
||||
.insertBefore($("#profilepane form"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#registerbtn").click(function() {
|
||||
$("#registerpane").find(".alert-error").remove();
|
||||
|
@ -276,6 +292,35 @@ $("#rpbtn").click(function() {
|
|||
|
||||
});
|
||||
|
||||
$("#profilesave").click(function() {
|
||||
$("#profilepane").find(".alert-error").remove();
|
||||
$("#profilepane").find(".alert-success").remove();
|
||||
var img = $("#profileimg").val();
|
||||
img = escape(img).replace(/\//g, "%2F")
|
||||
.replace(/&/g, "%26")
|
||||
.replace(/=/g, "%3D")
|
||||
.replace(/\?/g, "%3F");
|
||||
var url = api + "setprofile?" + [
|
||||
"name=" + uname,
|
||||
"session=" + session,
|
||||
"profile_image=" + img,
|
||||
"profile_text=" + escape($("#profiletext").val())
|
||||
].join("&") + "&callback=?";
|
||||
|
||||
$.getJSON(url, function(data) {
|
||||
if(data.success) {
|
||||
$("<div/>").addClass("alert alert-success")
|
||||
.text("Profile updated.")
|
||||
.insertBefore($("#profilepane form"));
|
||||
}
|
||||
else {
|
||||
$("<div/>").addClass("alert alert-error")
|
||||
.text(data.error)
|
||||
.insertBefore($("#profilepane form"));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#login").click(function() {
|
||||
if(!loggedin) {
|
||||
makeTabCallback("#login", "#loginpane")();
|
||||
|
|
Loading…
Reference in New Issue