Browse Source

added ability for users to delete their account

Akira Laine 9 năm trước cách đây
mục cha
commit
5d2baaef38
4 tập tin đã thay đổi với 26 bổ sung3 xóa
  1. 9 0
      app/client/app.css
  2. 10 2
      app/client/client.js
  3. 4 1
      app/client/templates/settings.html
  4. 3 0
      app/server/server.js

+ 9 - 0
app/client/app.css

@@ -1493,4 +1493,13 @@ input[type="checkbox"]:checked + #two-label:after {
 
 #submit-name{
     margin-left: 10px;
+}
+
+#submit-username{
+    margin-left: 10px;
+}
+
+.settings-option{
+    margin: 5px 0;
+    font-size: 1.2em;
 }

+ 10 - 2
app/client/client.js

@@ -92,6 +92,12 @@ function getSpotifyInfo(title, cb, artist) {
 Template.settings.events({
     "click #save-settings": function() {
         Meteor.call("updateSettings", $("#showRating").is(":checked"));
+    },
+    "click #delete-account": function(){
+        $("#delete-account").text("Click to confirm");
+        $("#delete-account").click(function(){
+            Meteor.call("deleteAccount", Meteor.userId());
+        })
     }
 });
 
@@ -266,7 +272,7 @@ Template.settings.onCreated(function() {
 curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};
 
 Handlebars.registerHelper('active', function(path) {
-    return curPath() == path ? 'active' : '';
+        return curPath() == path ? 'active' : '';
 });
 
 Template.header.helpers({
@@ -366,7 +372,9 @@ Template.register.events({
     },
 
     "click #github-login": function(){
-        Meteor.loginWithGithub({loginStyle: "redirect"});
+        Meteor.loginWithGithub({loginStyle: "redirect"}, function(err, res) {
+            console.log(err, res);
+        });
     }
 });
 

+ 4 - 1
app/client/templates/settings.html

@@ -4,9 +4,10 @@
         <h1 id="profile-name">{{username}}</h1>
         <div class="col-md-4 col-md-offset-4">
             <div class="panel panel-primary">
-                <div class="panel-heading">Basic Info</div>
+                <div class="panel-heading">General Settings</div>
                 <div class="panel-body">
                     <!--h3 class="text text-warning text-center">Unfortunately, there is currently nothing for you to edit.</h3-->
+                    <p class="settings-option">Liked & disliked songs</p>
                     <div class="checkbox">
                         <input class="checkbox-box" type="checkbox" id="showRating">
                         <label for="showRating" class="settings-label">
@@ -14,6 +15,8 @@
                         </label>
                     </div>
                     <button class="btn btn-warning btn-block" id="save-settings">Save</button>
+                    <p class="settings-option">Delete Account</p>
+                    <button class="btn btn-danger btn-block" id="delete-account">Delete</button>
                 </div>
             </div>
         </div>

+ 3 - 0
app/server/server.js

@@ -959,6 +959,9 @@ Meteor.methods({
     },
     updateUserName: function(username, newUserName){
         Meteor.users.update({"username": username}, {$set: {"username": newUserName, "profile.username": newUserName, "profile.usernameL": newUserName.toLowerCase()}})
+    },
+    deleteAccount: function(userID) {
+        Meteor.users.remove({_id: userID});
     }
 });