Commit bd78788b authored by mafolz's avatar mafolz
Browse files

inital commit

parents
# encoding: UTF-8
##
# Chronik-Eintrag, falls ein Quest durch einen Hacker gelöst wurde
class Earning < ActiveRecord::Base
# Begünstigter: Derjenige, für den die Punkte eingelöst werden,
# z.B. User x löst für hacker y 10 Punkte ein, da sich hacker y
# eine Limo geholt hat.
belongs_to :hacker
# Benutzer der diese Buchung durchführt hat
belongs_to :user, :class_name => 'Hacker'
belongs_to :quest
has_one(:cancel, lambda { where(:subject_type => 'Earning') }, {
:foreign_key => :subject_id
})
end
class Hacker < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :nickname, :uniqueness => true, :presence => true
has_many :earnings, :foreign_key => :hacker_id
has_many :redemptions, :foreign_key => :hacker_id
######################
## Instance Methods ##
######################
# Summe aller jemals eingelösten Punkte
def all_redeemed_points
return 2083
end
# Summe aller in den letzten 90 Tagen verdienten Punkte
def recent_earned_points
return 26
end
# Summe aller jemals verdienten Punkte,
# unabhängig davon, ob diese bereits
# eingelöst wurden oder nicht
def all_earned_points
return 2125
end
# Verbleibendes Guthaben, d.h. alle jemals verdienten Punkte
# abzüglich aller jemals eingelösten Punkte,
def remaining_points
return all_earned_points - all_redeemed_points
end
end
# enconding: UTF-8
##
# Eine zu lösende Aufgabe, z.B. 'Müll rausbringen' oder 'Boden wischen'
class Quest < ActiveRecord::Base
validates :points, :title, :presence => true
validates :points, :numericality => {:greater_than => 0}
end
# encoding: UTF-8
## Chronik-Eintrag, wenn Punkte durch einen Hacker eingelöst wurden
## (Eintausch gegen Naturalien)
class Redemption < ActiveRecord::Base
validates :hacker_id, :reward_id, :points, :presence => true
validates :points, :numericality => {:greater_than => 0}
# Begünstigter: Derjenige, dessen "Punktekonto" diese Punkte abgezogen werden
# Beispiel: User x ist angemeldet und löst für hacker y 10 Punkte ein,
# da hacker y sich eine Limo nimmt.
belongs_to :hacker
# Benutzer der diese Buchung durchführt hat
belongs_to :user, :class_name => 'Hacker'
belongs_to :reward
has_one(:cancel, lambda { where(:subject_type => 'Redemption') }, {
:foreign_key => :subject_id
})
end
# encoding: UTF-8
## Definiert eine Belohnung, die eingelöst werden kann,
# z.B. 'Chipstüte' oder 'Bier'
class Reward < ActiveRecord::Base
validates :points, :title, :presence => true
validates :points, :numericality => {:greater_than => 0}
end
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, :as => resource_name, :url => hacker_confirmation_path(), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Resend confirmation instructions" %></div>
<% end %>
<%= render "devise/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', hacker_confirmation_url(@resource, :confirmation_token => @token) %></p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_hacker_password_url(@resource, :reset_password_token => @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @token) %></p>
<h2>Change your password</h2>
<%= form_for(resource, :as => resource_name, :url => hacker_password_path(), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div><%= f.label :password, "New password" %><br />
<%= f.password_field :password, :autofocus => true %></div>
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Change my password" %></div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Forgot your password?</h2>
<%= form_for(resource, :as => resource_name, :url => hacker_password_path(), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, :as => resource_name, :url => hacker_registration_path(), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, :autocomplete => "off" %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password %></div>
<div><%= f.submit "Update" %></div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", hacker_registration_path(), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
<%= link_to "Back", :back %>
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => hacker_registration_path()) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :nickname %><br />
<%= f.text_field :nickname %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Sign in</h2>
<%= form_for(resource, :as => resource_name, :url => hacker_session_path()) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
<% end -%>
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render "devise/shared/links" %>
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_hacker_session_path() %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= %>
<%= link_to "Sign up", new_hacker_registration_path() %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_hacker_password_path() %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_hacker_confirmation_path() %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_hacker_unlock_path() %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(provider) %><br />
<% end -%>
<% end -%>
<h2>Resend unlock instructions</h2>
<%= form_for(resource, :as => resource_name, :url => unlock_path(), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Resend unlock instructions" %></div>
<% end %>
<%= render "devise/shared/links" %>
<div class="list-group">
<% chronicle.each do |entry| %>
<% if entry.kind_of?(Earning) %>
<div class="list-group-item row list-group-item-success">
<span class="col-md-2">
+<%= entry.points %>
</span>
<span class="col-md-2">
<%= l(entry.created_at, :format => :short) %>
</span>
<span class="col-md-4">
<%= entry.chronicle_text %>
</span>
<% if entry.cancel.blank? %>
<span class="btn btn-danger col-md-2">
<%= link_to 'Storno', '#' %>
</span>
<% end %>
</div>
<% if entry.cancel.present? %>
<%= render({
:partial => 'hackers/chronicle/earning_cancel',
:locals => {:entry => entry.cancel}
}) %>
<% end %>
<% elsif entry.kind_of?(Redemption) %>
<div class="list-group-item list-group-item-warning row">
<span class="col-md-1"></span>
<span class="col-md-1">
+<%= entry.points %>
</span>
<span class="col-md-2">
<%= l(entry.created_at, :format => :short) %>
</span>
<span class="col-md-4">
<%= entry.chronicle_text %>
</span>
<% if entry.cancel.blank? %>
<span class="btn btn-danger col-md-2">
<%= link_to 'Storno', '#' %>
</span>
<% end %>
</div>
<% if entry.cancel.present? %>
<%= render({
:partial => 'hackers/chronicle/redemption_cancel',
:locals => {:entry => entry.cancel}
}) %>
<% end %>
<% end %>
<% end %>
</div>
<% quests.in_groups_of(10) do |grouped_quests| %>
<div class="row">
<% grouped_quests.each do |quest| %>
<% if quest.present? %>
<div class="well col-md-2">
<h4>
<%= quest.title %>
</h4>
<!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= quest.image_url %>"> </span>
<%= quest.points %>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% rewards.in_groups_of(10) do |grouped_rewards| %>
<div class="row">
<% grouped_rewards.each do |reward| %>
<% if reward.present? %>
<div class="well col-md-2">
<h4>
<%= reward.title %>
</h4>
<!-- TODO: should be replaced with paperclip gem -->
<span class="glyphicon <%= reward.image_url %>"> </span>
<%= reward.points %>
</div>
<% end %>
<% end %>
</div>
<% end %>
<div class="list-group-item list-group-item-danger row">
<span class="col-md-2">
<%= entry.points %>
</span>
<span class="col-md-3">
<%= l(entry.created_at, :format => :short) %>
</span>
<span class="col-md-6">
<%= entry.chronicle_text %>
</span>
</div>
Supports Markdown
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