more fixes, changes, support for new mojang API
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
$(function(){
|
||||
hljs.initHighlightingOnLoad();
|
||||
$('.flash').click(function(){
|
||||
$('.flash').animate({
|
||||
opacity: 0
|
||||
|
||||
@@ -12,4 +12,6 @@
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require app
|
||||
//= require moment
|
||||
//= require moment
|
||||
//= require highlight
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
*= require style.css
|
||||
*= require screen.css
|
||||
*= require mobi.css
|
||||
*= require highlight/default.css
|
||||
*/
|
||||
@@ -59,7 +59,7 @@ class ForumgroupsController < ApplicationController
|
||||
private
|
||||
|
||||
def group_params(add = [])
|
||||
a = [:name, :position, :role_read, :role_write] + add
|
||||
a = [:name, :position, :role_read_id, :role_write_id] + add
|
||||
params.require(:forumgroup).permit(a)
|
||||
end
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ class ForumsController < ApplicationController
|
||||
|
||||
def create
|
||||
if admin?
|
||||
@forum = Forum.new(forum_params)
|
||||
@forum.forumgroup = Forumgroup.find(params[:forum][:forumgroup_id])
|
||||
@forum = Forum.new(forum_params([:forumgroup_id]))
|
||||
if @forum.save
|
||||
flash[:notice] = "Forum created."
|
||||
redirect_to @forum
|
||||
@@ -66,7 +65,7 @@ class ForumsController < ApplicationController
|
||||
end
|
||||
|
||||
def forum_params(add = [])
|
||||
a = [:name, :position, :role_read, :role_write] + add
|
||||
a = [:name, :position, :role_read_id, :role_write_id] + add
|
||||
params.require(:forum).permit(a)
|
||||
end
|
||||
end
|
||||
@@ -36,10 +36,9 @@ class ForumthreadsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@thread = Forumthread.new(mod? ? thread_params([:sticky, :locked]) : thread_params)
|
||||
@thread = Forumthread.new(mod? ? thread_params([:sticky, :locked, :forum_id]) : thread_params([:forum_id]))
|
||||
if @thread.can_write?(current_user)
|
||||
@thread.user_author = current_user
|
||||
@thread.forum = @thread.forum
|
||||
if @thread.save
|
||||
flash[:notice] = "Thread created!"
|
||||
redirect_to forumthread_path( @thread)
|
||||
@@ -71,6 +70,6 @@ class ForumthreadsController < ApplicationController
|
||||
def thread_params(add = [])
|
||||
a = [:title, :content]
|
||||
a += add
|
||||
params.require(:Forumthread).permit(a)
|
||||
params.require(:forumthread).permit(a)
|
||||
end
|
||||
end
|
||||
@@ -8,6 +8,10 @@ class Threadreply < ActiveRecord::Base
|
||||
validates_presence_of :content
|
||||
validates_length_of :content, in: 2..10000
|
||||
|
||||
def thread
|
||||
forumthread
|
||||
end
|
||||
|
||||
def author
|
||||
@author ||= if self.user_author.present?
|
||||
user_author
|
||||
|
||||
@@ -136,17 +136,23 @@ class User < ActiveRecord::Base
|
||||
# end
|
||||
|
||||
def get_profile
|
||||
uri = URI.parse("https://api.mojang.com/profiles")
|
||||
uri = URI.parse("https://api.mojang.com/profiles/minecraft")
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.open_timeout = 5
|
||||
http.read_timeout = 20
|
||||
http.use_ssl = true
|
||||
|
||||
payload = { agent: "Minecraft", name: self.ign }
|
||||
begin
|
||||
response = http.post(uri.request_uri, payload.to_json, "Content-Type" => "application/json")
|
||||
response = http.post(uri.request_uri, [self.ign].to_json, "Content-Type" => "application/json")
|
||||
if response.code == "200"
|
||||
return JSON.load(response.body)["profiles"][0]
|
||||
data = JSON.load(response.body)
|
||||
if data.length == 1
|
||||
return data[0]
|
||||
elsif data.length > 1
|
||||
raise "Multiple accounts for user #{self.ign}: '#{response.body}'"
|
||||
elsif data.length < 1
|
||||
return nil
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
puts "----"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= link_to @forum.group, forumgroup_path(@forum.group) %> → <%= link_to @forum.name, @forum %>
|
||||
<%= link_to "(Edit) #{@forum.group.name}", edit_forumgroup_path(@forum.group) %> → <%= link_to @forum.name, @forum %>
|
||||
<h1>Edit Forum</h1>
|
||||
<% role_selection = Role.all_from_to(:normal, :admin).collect{|p|[p.name, p.id]} %>
|
||||
<%= form_for @forum do |f|%>
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
<div class="items bold">
|
||||
<% group.forums.each do |f| %>
|
||||
<%= link_to f.name, f, class: "item" %>
|
||||
<% if f.can_read?(current_user) %>
|
||||
<%= link_to f.name, f, class: "item" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
<td><%= f.select :role_write_id, role_selection, include_blank: false %></td>
|
||||
</tr>
|
||||
</table>
|
||||
<%= f.hidden_field :forumgroup_id, value: @forum.group.id %>
|
||||
<%= f.hidden_field :forumgroup_id %>
|
||||
<p><%= f.submit "Create forum", class: "btn blue" %></p>
|
||||
<% end %>
|
||||
@@ -17,5 +17,6 @@
|
||||
<%= f.text_field :title, placeholder: "Title" %>
|
||||
</div>
|
||||
<%= f.text_area :content, placeholder: "Text" %>
|
||||
<%= f.hidden_field :forum_id %>
|
||||
<p><%= f.submit "Create thread", class: "btn blue" %></p>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user