     (auth/set-user! db nil)))
 
 (register-handler-for
-  :login
-  (fn [db user-pwd]
-    (let [sign-in api/signin]
-      (sign-in :user {:username (:user user-pwd) :password (:pwd user-pwd)}
-               :on-success (fn [user-res] (dispatch [:auth-success (:data user-res)] ))
-               :on-error
-               #(condp = (:type %)
-                   :invalid-credentials (dispatch [:auth-fail])
-                   :network-error (dispatch [:set-offline true])
-                   (dispatch [:unknown-error])))
-
-      (-> db
-          (auth/set-in-progress! true)
-          (auth/set-user!        nil)
-          (auth/set-error!       nil)))))
+ :login
+ (fn [db user-pwd]
+   (let [sign-in api/signin]
+     (sign-in :user {:username (:user user-pwd) :password (:pwd user-pwd)}
+              :on-success (fn [user-res] (dispatch [:auth-success (:data user-res)]))
+              :on-error
+              #(condp = (:type %)
+                 :invalid-credentials (dispatch [:auth-fail])
+                 :network-error (dispatch [:set-offline true])
+                 (dispatch [:unknown-error])))
+
+     (-> db
+         (auth/set-in-progress! true)
+         (auth/set-user!        nil)
+         (auth/set-error!       nil)))))
+
+(register-api-call-handler
+ :begin-api-event-key  :auth/login
+ :api-call             api/signin
+ :init-fn              (fn [db user]
+                         (-> db
+                             (auth/set-user!  nil)
+                             (auth/set-error! nil)))
+ :params-fn            (fn [db user-pwd]
+                         {:user {:username (:user user-pwd) :password (:pwd user-pwd)}})
+ :success-fn           (fn [db user]
+                         (when (= (:page db) "login")
+                           (dispatch [:set-page :inbox]))
+                         (-> db
+                             (auth/set-user! user)))
+ :error-fn             (fn [db]
+                         (-> db
+                             (auth/set-error! "Authentication failed")))
+ )
 
 (register-handler-for
   :auth-fail

        (auth/set-in-progress! false)
        (auth/set-user!        nil)
        (auth/set-error!       "Authentication failed"))))


(register-handler-for
  :auth-success

     (get-messages
      :on-success (fn [data]
                    (dispatch [:inbox/fetch-success (:data data)] ))
      :on-error
      #(condp = (:type %)
         :invalid-credentials (dispatch [:logout])
         :network-error       (do (dispatch [:set-offline true])
                                  (dispatch :inbox/fetch-fail))
         (dispatch [:unknown-error])))
     db)))

(register-handler-for
