110
112
% maybe we can use hovercraft to simplify running this view query
111
113
get_user(Db, UserName) ->
112
DesignId = <<"_design/_auth">>,
113
ViewName = <<"users">>,
114
% if the design doc or the view doesn't exist, then make it
115
ensure_users_view_exists(Db, DesignId, ViewName),
117
case (catch couch_view:get_map_view(Db, DesignId, ViewName, nil)) of
118
{ok, View, _Group} ->
120
({{Key, _DocId}, Value}, _, nil) when Key == UserName -> {ok, Value};
121
(_, _, Acc) -> {stop, Acc}
123
case couch_view:fold(View, {UserName, nil}, fwd, FoldlFun, nil) of
124
{ok, {Result}} -> Result;
127
{not_found, _Reason} ->
129
% case (catch couch_view:get_reduce_view(Db, DesignId, ViewName, nil)) of
130
% {ok, _ReduceView, _Group} ->
132
% {not_found, _Reason} ->
114
% In the future this will be pluggable. For now we check the .ini first,
115
% then fall back to querying the db.
116
io:format("~n~nget-user: '~p'~n", [get_user]),
117
case couch_config:get("admins", ?b2l(UserName)) of
118
"-hashed-" ++ HashedPwdAndSalt ->
119
io:format("hashed: '~p'~n", [hashed]),
120
[HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","),
121
[{<<"roles">>, [<<"_admin">>]},
122
{<<"salt">>, ?l2b(Salt)},
123
{<<"password_sha">>, ?l2b(HashedPwd)}];
125
DesignId = <<"_design/_auth">>,
126
ViewName = <<"users">>,
127
% if the design doc or the view doesn't exist, then make it
128
ensure_users_view_exists(Db, DesignId, ViewName),
130
case (catch couch_view:get_map_view(Db, DesignId, ViewName, nil)) of
131
{ok, View, _Group} ->
133
({{Key, _DocId}, Value}, _, nil) when Key == UserName -> {ok, Value};
134
(_, _, Acc) -> {stop, Acc}
136
case couch_view:fold(View, {UserName, nil}, fwd, FoldlFun, nil) of
137
{ok, {Result}} -> Result;
140
{not_found, _Reason} ->
142
% case (catch couch_view:get_reduce_view(Db, DesignId, ViewName, nil)) of
143
% {ok, _ReduceView, _Group} ->
145
% {not_found, _Reason} ->
137
151
ensure_users_db_exists(DbName) ->