parsav  Diff

Differences From Artifact [0d69ec17a3]:

To Artifact [671b92715b]:


     1      1   -- vim: ft=terra
            2  +local pstr = lib.mem.ptr(int8)
            3  +local P = lib.str.plit
     2      4   local terra 
     3         -login_form(co: &lib.srv.convo, user: &lib.store.actor, creds: &lib.store.credset, msg: &int8)
            5  +login_form(co: &lib.srv.convo, user: &lib.store.actor, creds: &lib.store.credset, msg: pstr)
     4      6   	var doc = data.view.docskel {
     5         -		instance = co.srv.cfg.instance.ptr;
     6         -		title = 'instance logon';
     7         -		class = 'login';
     8         -		navlinks = co.navbar.ptr;
            7  +		instance = co.srv.cfg.instance;
            8  +		title = lib.str.plit 'instance logon';
            9  +		class = lib.str.plit 'login';
           10  +		navlinks = co.navbar;
     9     11   	}
    10     12   
    11     13   	if user == nil then
    12     14   		var form = data.view.login_username {
    13     15   			loginmsg = msg;
    14     16   		}
    15         -		if form.loginmsg == nil then
    16         -			form.loginmsg = 'identify yourself for access to this instance.'
           17  +		if form.loginmsg.ptr == nil then
           18  +			form.loginmsg = lib.str.plit 'identify yourself for access to this instance.'
    17     19   		end
    18         -		var formtxt = form:tostr()
    19         -		doc.body = formtxt.ptr
           20  +		doc.body = form:tostr()
    20     21   	elseif creds:sz() == 0 then
    21     22   		co:complain(403,'access denied','your host is not eligible to authenticate as this user')
    22     23   		return
    23     24   	elseif creds:sz() == 1 then
    24     25   		if creds.trust() then
    25     26   			-- TODO log in immediately
    26     27   			return
................................................................................
    27     28   		end
    28     29   
    29     30   		var ch = data.view.login_challenge {
    30     31   			handle = user.handle;
    31     32   			name = lib.coalesce(user.nym, user.handle);
    32     33   		}
    33     34   		if creds.pw() then
    34         -			ch.challenge = 'enter the password associated with your account'
    35         -			ch.label = 'password'
    36         -			ch.method = 'pw'
           35  +			ch.challenge = P'enter the password associated with your account'
           36  +			ch.label = P'password'
           37  +			ch.method = P'pw'
    37     38   		elseif creds.otp() then
    38         -			ch.challenge = 'enter a valid one-time password for your account'
    39         -			ch.label = 'OTP code'
    40         -			ch.method = 'otp'
           39  +			ch.challenge = P'enter a valid one-time password for your account'
           40  +			ch.label = P'OTP code'
           41  +			ch.method = P'otp'
    41     42   		elseif creds.challenge() then
    42         -			ch.challenge = 'sign the challenge token: <code>...</code>'
    43         -			ch.label = 'digest'
    44         -			ch.method = 'challenge'
           43  +			ch.challenge = P'sign the challenge token: <code>...</code>'
           44  +			ch.label = P'digest'
           45  +			ch.method = P'challenge'
    45     46   		else
    46     47   			co:complain(500,'login failure','unknown login method')
    47     48   			return
    48     49   		end
    49     50   
    50         -		doc.body = ch:tostr().ptr
           51  +		doc.body = ch:tostr()
    51     52   	else
    52     53   		-- pick a method
    53     54   	end
    54     55   
    55     56   	var hdrs = array(
    56     57   		lib.http.header { 'Content-Type', 'text/html; charset=UTF-8' }
    57     58   	)
    58     59   	doc:send(co.con,200,[lib.mem.ptr(lib.http.header)] {ct = 1, ptr = &hdrs[0]})
    59         -	lib.mem.heapf(doc.body)
           60  +	doc.body:free()
    60     61   end
    61     62   
    62     63   return login_form