<commit_before>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FILE: surrogate_landing_controller.erl
%
% AUTHOR: <NAME>
% DATE: 5-20-15
%
% DESCRIPTION:
%
% Controller for the landing page.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-module(surrogate_landing_controller, [Req]).
-compile(export_all).

config('GET', []) ->
	case boss_db:find(config, [{id, 1}], [{limit,1}]) of
		[Config] ->
			{redirect, "/login/login", account:login_cookies()};
		[] -> 
			Config = config:new(id, false, "/opt/surrogate", 3),
			{ok, [{config, Config}]}
	end;

config('POST', []) ->
	Config = config:new(id, Req:post_param("autoStart"), Req:post_param("downloadDirectory"), Req:post_param("numSimultaneousDownloads")),
	Account = account:new(id, Req:post_param("userName"), account_lib:create_password_hash(Req:post_param("password"), Req:post_param("userName"))),
	case Account:save() of
        {ok, SavedAccount} ->
			case Config:save() of
				{ok, SavedConfig} ->
            		{redirect, "/login/login/", {userName, SavedAccount:get_username()}};				
				{error, Errors} ->
				   {ok, [{errors, Errors}, {config, Config}]}
			end;
        {error, Errors} ->
           {ok, [{errors, Errors}, {config, Config}]}
    end.<commit_msg>Updated the landing controller to redirect after initial config post.<commit_after>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FILE: surrogate_landing_controller.erl
%
% AUTHOR: <NAME>
% DATE: 5-20-15
%
% DESCRIPTION:
%
% Controller for the landing page.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-module(surrogate_landing_controller, [Req]).
-compile(export_all).

config('GET', []) ->
	case boss_db:find(config, [{id, 1}], [{limit,1}]) of
		[Config] ->
			{redirect, "/login/login", account:login_cookies()};
		[] -> 
			Config = config:new(id, false, "/opt/surrogate", 3),
			{ok, [{config, Config}]}
	end;

config('POST', []) ->
	Config = config:new(id, Req:post_param("autoStart"), Req:post_param("downloadDirectory"), Req:post_param("numSimultaneousDownloads")),
	Account = account:new(id, Req:post_param("userName"), account_lib:create_password_hash(Req:post_param("password"), Req:post_param("userName"))),
	case Account:save() of
        {ok, SavedAccount} ->
			case Config:save() of
				{ok, SavedConfig} ->
            		{redirect, "/login/login/", []};				
				{error, Errors} ->
				   {ok, [{errors, Errors}, {config, Config}]}
			end;
        {error, Errors} ->
           {ok, [{errors, Errors}, {config, Config}]}
    end.
{'fraction_non_alphanumeric': 0.25211097708082025, 'fraction_numerical': 0.006433453960595094, 'mean_word_length': 4.603603603603603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5555844', 'n_tokens_mistral': 919, 'n_tokens_neox': 832, 'n_words': 160}