<%!
from kaithem.src import auth, pages,unitsofmeasure
import pytz
%>
<%include file="/pageheader.html"/>
<h1>My Account</h1>
<details class="help"><summary><i class="mdi mdi-help-circle-outline"></i></summary>Note: Your changes are saved temporarily to RAM until either a configured autosave(Off by default), or a manual save of the server state.</details>
<h2>Security</h2>
<div class="window paper">
Restricted to LAN IP addresses(Only admin can change): ${auth.getUserSetting(pages.getAcessingUser(), 'restrict-lan')}</br>




<h3>Change Password</h3>
<form action='/settings/changepwd' method='post'>
<table border=1>

<tr><td>Current Password</td><td><input name="old" type ="password"></input></td></tr>
<tr><td>New Password</td><td><input name="new" type ="password"></input></td></tr>
<tr><td>Retype New Password</td><td><input name="new2" type ="password"></input></td></tr>
</table>
<input type ="submit" value="Change Password"></input>
</form>
</div>

<h2>Basic Info</h2>
<div class="window paper">
<form action='/settings/changeinfo' method='post'>
<h3>Contact Info</h3>
<table border=1>
<tr>
<td>Email Address</td><td><input type="email" name="email" value="${auth.getUserSetting(pages.getAcessingUser(),'email')}"
</tr>
</table>
<input type="submit" value="Save">
</form>
</div>
<form action='/settings/changeprefs' method='post'>


<div class="window paper">

<h2>Web Services</h2>
<h3>CORS Access</h3>
Allow CORS access as this user: <input type="checkbox" name="allowcors"

                                    %if auth.getUserSetting(pages.getAcessingUser(), 'allow-cors'):
                                    checked="on"
                                    %endif
                                    ></input>

 <input type="submit" value="Save"></input>

</div>
<h2>Time Formatting(Current: <span style="color: darkgreen">${unitsofmeasure.strftime()}</span>)</h2>
<div class="window paper">
<table border=1>
<%tz = auth.getUserSetting(pages.getAcessingUser(),'timezone')%>
<tr>
<td>Time Zone</td><td><select name="pref_timezone">
%for i in pytz.common_timezones:
    <option value="${i}"
    %if i==tz:
    selected\
    %endif
    >
    ${i}
    </option>
%endfor
</select></td>
</tr>

<td>strftime String</td><td><input name="pref_strftime" value="${auth.getUserSetting(pages.getAcessingUser(),'strftime')|h}"></input>(Default: %a, %b %d, %Y at %I:%M:%S %p %Z)</td>
</table>

<input type ="submit" value="Save"></input>
</div>


<h2>My Permissions</h2>
<div class="window paper">
<details class="help"><summary><i class="mdi mdi-help-circle-outline"></i></summary>These are the permissions you have been granted.</details>
%for i in sorted(auth.Users[pages.getAcessingUser()].permissions):
<h3
%if i.startswith('__'):
class="specialentry"\
%endif
>${i|h}
</h3>
%if i in auth.Permissions:
    %if isinstance(auth.Permissions[i],str):
    ${auth.Permissions[i]|h}
    %else:
    ${auth.Permissions[i].get("description",'No description found')|h}
    %endif
%else:
    "Unknown"
%endif
%endfor
<h3>My Upload Limit</h3>
You can currently make HTTP requests containing up to ${unitsofmeasure.si_format_number(auth.getUserLimit(pages.getAcessingUser(),"web.maxbytes"))}b
</div>

%try:
<h3>Login History</h3>
<div class="window paper">
%for i in (auth.Users[pages.getAcessingUser()]['loginhistory']):
<b>${unitsofmeasure.strftime(i[0])|h}: login from ${i[1]|h}</b><br>
%endfor
</div>
%except:
%endtry


</form>

<%include file="/pagefooter.html"/>
