Skip to content

Commit 0692fc6

Browse files
committed
Remove post password
1 parent 7fb250f commit 0692fc6

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

PostModel.py

+6
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,11 @@ def generateImage(self, size_w, size_h, filename, ex):
266266
im.thumbnail(size, Image.ANTIALIAS)
267267
im.save(UPLOAD_FOLDER + ex + filename, "JPEG")
268268

269+
def postRemovePass(self, id):
270+
from models import db
271+
p = self.Post.query.filter_by(Id=id).first()
272+
p.Password = 'NULL'
273+
db.session.commit()
274+
269275

270276

controllers/admin.py

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ def deletepost(id=None):
126126
post.deletePost(id)
127127
return redirect("/admin")
128128

129+
@admin_api.route('/admin/remove-password', methods=['POST'])
130+
def removepassword():
131+
if request.json['id']:
132+
post = PostModel()
133+
post.postRemovePass(request.json['id'])
134+
response = {'status': 1, 'message': "Deleted"}
135+
136+
return json.jsonify(response)
137+
129138

130139
@admin_api.route('/admin/users', methods=['GET'])
131140
def users():

templates/admin/add-post.html

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<input type="text" name="slug" {% if post %} value="{{post.Slug}}" {% endif%} class="form-control" placeholder="Slug" />
1313
</div>
1414
<div class="form-group">
15+
{% if post %} {% if post.Password != 'NULL' %} <a href="javascript: void(0);" onclick="javscript: removePassword('{{post.Id}}', $(this))">Remove password</a> {% endif%} {% endif%}
1516
<input type="password" name="password" class="form-control" placeholder="Post password" />
1617
</div>
1718
<div class="form-group">
@@ -141,6 +142,27 @@
141142
});
142143
}
143144
}
145+
function removePassword(id, el){
146+
var g = id;
147+
var id = {id:id}
148+
149+
if(id){
150+
151+
$.ajax({
152+
type : "POST",
153+
url : "/admin/remove-password",
154+
data: JSON.stringify(id, null, '\t'),
155+
contentType: 'application/json;charset=UTF-8',
156+
success: function(result) {
157+
if(result.status){
158+
el.remove();
159+
160+
}
161+
}
162+
});
163+
}
164+
}
165+
144166
</script>
145167
<style>
146168
.redactor_box{

0 commit comments

Comments
 (0)