{% extends "control/control_base.html" %}

{% comment %}
<Program>
  profile.html
  
<Author>
  Originally by?:
  Justin Samuel 2009

  Modified:
  Gaetano Pressimone Aug 2012
  
<Purpose>
  Django template file for Seattle Clearinghouse's 'Profile' page.  The page 
  shows user information and also allows editing of certain user fields.

<extends>
  control/control_base.html

<Stylesheet>
  common.css
  profile.css

<Scripts>
  edit_profile.js

<Template Variables>
  email_form:
    The form to change a user's email address.

  affiliation_form:
    The form to change a user's affiliation.

  password_form:
    The form to change a user's password.

  username:
		The currently logged in user.

  affiliation: 
		The logged in user's affiliation.

  email: 
		The logged in user's email address.

  port:
		The logged in user's port number.

  api_key: 
		The logged in user's api key.

  has_privkey: 
		Boolean value regarding if a user has deleted his private key or not.

  info:
		Message related to profile actions example-changing password.

  error_msg:
		Error message related to profile actions.

  messages:
    Django Social Auth error msg.

  social_auth
    Object containing info related to the logged in user's OpenID/OAuth
    assocations.
    .not_associated
      All openid/oauth providers not associated with the logged in user.
    .backends
      All associated backends(facebook etc.) from the logged in user.
    .associated
      All associated backends organized by type (.oauth, .openid, .oauth2).

{% endcomment %}

{% block style %}
{{ block.super }}
<link href="{{ MEDIA_URL }}css/profile.css" rel="stylesheet" type="text/css" />
{% endblock style %}

{% block script %}
{{ block.super }}
<script type="text/javascript" src="{{ MEDIA_URL }}scripts/edit_profile.js" charset="utf-8"></script>
{% endblock script %}

{% block title %}
Profile - Seattle Clearinghouse
{% endblock title %}

{% block nav_profile %}
<td class="active"><a href="{% url profile %}">Profile</a></td>
{% endblock nav_profile %}

{% block content %}
	<div id="main">
		<div id="middle">
		
			<div id="download">
				<a href="http://seattleclearinghouse.poly.edu/dist/demokit.zip"><img src="{{ MEDIA_URL }}images/download_demokit.jpg" alt="Download demokit"/>Download demokit</a>
			</div>
			
		   <table class="profile">          
				{% if info %}
				<tr class="even">
					<td colspan="2">
						<div id="info">{{ info }}</div>
					</td>
				</tr>
				{% endif %}
				{% if password_form.non_field_errors or email_form.errors or affiliation_form.errors or error_msg or messages %}
				<tr class="even">
					<td colspan="2">
						<div id="error_msg">
							{{ password_form.non_field_errors }}
							{{ email_form.email.errors }}
							{{ affiliation_form.affiliation.errors }}
							{{ error_msg }}
							{% for msg in messages %}
								{% if msg.message %}
									{{ msg.message }} ({{ msg.extra_tags }})
								{% endif %}
							{% endfor %}
						</div>
					</td>
				</tr>
				{% endif %}
			    <tr class="odd">
					<td class="key">Username</td>
					<td class="value">{{ username }}</td>
			    </tr>
			    <tr class="even">
					<td class="key">Password</td>
					<td class="value"> <button class="edit" type="button" title="Password">Edit</button>
						<span class="value">********</span>
						<span class="hide_this">
							<form action="{% url profile %}" method="POST">
								<table id="edit_password">
									<tr>
										<td>Enter password: </td>
										<td class="field"> {{ password_form.password1 }}</td>
									</tr>
									<tr>
										<td>Confirm password: </td>
										<td class="field"> {{ password_form.password2 }} <input type="submit" value="Save"/> </td>
									</tr>
								</table>
							</form>
						</span>	
					</td>
			    </tr>
			    <tr class="odd">
					<td class="key">Affiliation</td>
					<td class="value">
						<span class="value">{{ affiliation }}</span>
						<span class="hide_this">
							<form  action="{% url profile %}" method="POST">
								{{ affiliation_form.affiliation }}
								<input type="submit" value="Save"/>
							</form>
						</span>
						<button class="edit" type="button" title="Affiliation">Edit</button>
					</td>
				</tr>
				<tr class="even">
					<td class="key">E-mail Address<img class="help" src="{{ MEDIA_URL }}images/help-icon.png"title="If you forget your password this email will be used to recover your account. The Clearinghouse does not use your email for anything else."/></td>
					<td class="value">
						<span class="value" >{{ email }} </span>
						<span class="hide_this">
							<form action="{% url profile %}" method="POST">
								{{ email_form.email }}
								<input type="submit" value="Save"/>
							</form>
						</span>
						<button class="edit" type="button"title="E-mail">Edit</button>
					</td>
				</tr>
				<tr class="odd">
					<td class="key">API Key
						<img class="help" src="{{ MEDIA_URL }}images/help-icon.png"title="The Clearinghouse offers an API key that allows applications to perform actions on your behalf, such as acquiring, releasing, and renewing vessels.  If this key is lost or stolen, you can reset it at any time."/></td>
					<td class="value api_cell"> 
							<span class="api_cell" title="double click to show"><i>double click to show</i></span>
							<span id="api_key" class="hide_this" title="double click to hide">{{ api_key }}</span>
							<form action="{% url api_info %}" method="post">
							<input type="hidden" name="generate_api_key" value="yes"/>
							<button id="generate_api" type="submit"title="In some cases you may want to generate a new API key (for example, if you accidentally left your old one in a file that you shared publicly). Generating a new API key will make your old API key no longer work.">Generate new API Key</button>
							</form>
					</td>
				</tr>
				<tr class="even">
					<td class="key">Port <img class="help" src="{{ MEDIA_URL }}images/help-icon.png"title="This indicates a port number that by default will be available for TCP / UDP on all of your acquired vessels."/></td>
					<td class="value">{{ port }}</td>
				</tr>
				<tr class="odd">
					<td class="key">Linked Accounts<img class="help" src="{{ MEDIA_URL }}images/help-icon.png"title="When you link an account you may then use it to log in to the Clearinghouse."/></td>
					<td class="value">
					      
        	  {% for type, accounts in social_auth.associated.items %}
  					  {% for account in accounts %}
								{% if account.provider == "facebook"%}
									<img src="{{ MEDIA_URL }}images/Facebook-icon.png" title="Facebook account linked" />
								{% endif %}
								{% if account.provider == "google"%}
									<img src="{{ MEDIA_URL }}images/google-icon.png" title="Gmail account linked" />
								{% endif %}
								{% if account.provider == "github"%}
									<img src="{{ MEDIA_URL }}images/github-icon.png" title="Github account linked" />
								{% endif %}
								{% if account.provider == "live"%}
									<img src="{{ MEDIA_URL }}images/windows-icon.png" title="Windows Live account linked" />
								{% endif %}
								{% if account.provider == "yahoo"%}
									<img src="{{ MEDIA_URL }}images/yahoo-icon.png" title="Yahoo account linked" />
								{% endif %}
     						 {% comment %}  <span class="disconnect">
											<a href={% url socialauth_disconnect_individual account.provider account.id %}>
												{{ account.provider|title }} (ID {{ account.id }})<br/></a></span> 
								 {% endcomment %}
   					 {% endfor %}
 					 {% endfor %}
					
				{% for name, accounts in social_auth.not_associated.items %}
					{% for name in accounts %}
				  	<a rel="nofollow" href="{% url socialauth_begin name %}">
				    	{% if name == "facebook"%}
				  		 <img src="{{ MEDIA_URL }}images/bw-Facebook-icon.png" title="A Facebook account is not yet associated, click to link it!"/>
					    {% endif %}
				    	{% if name == "google"%}
					    	<img src="{{ MEDIA_URL }}images/bw-google-icon.png" title="A Google account is not yet associated, click to link it!"/>
				    	{% endif %}
				    	{% if name == "github"%}
				    		<img src="{{ MEDIA_URL }}images/bw-github-icon.png" title="A Github account is not yet associated, click to link it!"/>
			    		{% endif %}
			    		{% if name == "live"%}
			    			<img src="{{ MEDIA_URL }}images/bw-windows-icon.png" title="A Windows Live account is not yet associated, click to link it!"/>
			    		{% endif %}
			    		{% if name == "yahoo"%}
				    		<img src="{{ MEDIA_URL }}images/bw-yahoo-icon.png" title="A Yahoo account is not yet associated, click to link it!"/>
				    	{% endif %}
			  		</a>
			  	{% endfor %}
  	  	{% endfor %}
				  </td>
		    	</table> <br/>
		<table class="profile">
			<tr>
				<td><h3>Your Keys</h3></td>
				<td> <form id="change_key" action="{% url change_key %}" method="post"style="display:inline;">
					<input type="hidden" name="generate" value="yes"/>
					<button id="generate_keypair" type="submit" title="The Clearinghouse can generate a new key pair for you. After it is generated, you will need to download your public and private keys again." style=""> Generate new Key Pair</button>
						</form>
			</td> 
			</tr>
		</table>
	<h1></h1>
		<table class="profile">
			<tr class="odd">
				<td class="key">Public Key
					<img class="help" src="{{ MEDIA_URL }}images/help-icon.png"
								title="If you have generated a key pair on your own computer(for example, using Seash), you can upload your public key here. Do not upload your private key."/></td>
				<td class="value">
					<span class="value">********</span>
					<span class="hide_this">
						<button type="button" class="cancel" title="Cancel"> Cancel </button>
						<form action="{% url change_key %}" method="post" enctype="multipart/form-data">
							<input type="file" name="pubkey"/> <button type="submit" title="Upload a public key">Upload</button>
						</form>
					</span>
					<form method="POST" action="{% url pub_key %}" id="download_pubkey_form"> 
						<button type="submit" class="download" title="Download your public key"> Download </button>
					 </form>
						<button id="show_keyform" type="button" title="Upload a public key"> Upload </button>
				</td>
			</tr>
				{% if has_privkey %}
				<tr class="even">
					<td class="key">Private Key <img class="help" src="{{ MEDIA_URL }}images/red-help-icon.png"title="The Clearinghouse does not need your private key to provide you access to vessels.  You may wish to download this key and then delete it from the server."/></td>
					<td class="value">********<a href="#">
						<form class="inline" method="POST" action="{% url priv_key %}">
							<button type="submit" title="Download your private key">Download </button>
						</form>
						<form class="inline" method="POST" action="{% url del_priv %}">
							<input type="hidden" name="keyToDelete" value={{ username }}/>
							<button id="delete" type="submit" title="Delete your private key">Delete </button>
						</form>
					</td>
				</tr>
				<tr class="odd">
					<td colspan="2">
            <img id="up_arrow" src="{{ MEDIA_URL }}/images/red-up-arrow.png" />
						<p class="warning"> For better
						security we recommend that you
						download and delete your 
						private key from the 
						server. Always store your 
						private key in a secure 
						location. </p>
					</td>
				</tr>
				{% endif %}
			</table>
		</div>
	</div>
{% endblock content %}
