From f9a3a4b3949dddecae413b97904c895b2cd887bf Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Wed, 30 Mar 2016 12:49:29 -0400
Subject: Add MFA functionality

---
 webapp/utils/client.jsx | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

(limited to 'webapp/utils/client.jsx')

diff --git a/webapp/utils/client.jsx b/webapp/utils/client.jsx
index d42767d31..a596d1e14 100644
--- a/webapp/utils/client.jsx
+++ b/webapp/utils/client.jsx
@@ -337,13 +337,28 @@ export function logout(success, error) {
     });
 }
 
-export function loginByEmail(name, email, password, success, error) {
+export function checkMfa(method, team, loginId, success, error) {
+    $.ajax({
+        url: '/api/v1/users/mfa',
+        dataType: 'json',
+        contentType: 'application/json',
+        type: 'POST',
+        data: JSON.stringify({method, team_name: team, login_id: loginId}),
+        success,
+        error: function onError(xhr, status, err) {
+            var e = handleError('checkMfa', xhr, status, err);
+            error(e);
+        }
+    });
+}
+
+export function loginByEmail(name, email, password, token, success, error) {
     $.ajax({
         url: '/api/v1/users/login',
         dataType: 'json',
         contentType: 'application/json',
         type: 'POST',
-        data: JSON.stringify({name, email, password}),
+        data: JSON.stringify({name, email, password, token}),
         success: function onSuccess(data, textStatus, xhr) {
             track('api', 'api_users_login_success', data.team_id, 'email', data.email);
             sessionStorage.removeItem(data.id + '_last_error');
@@ -381,13 +396,13 @@ export function loginByUsername(name, username, password, success, error) {
     });
 }
 
-export function loginByLdap(teamName, id, password, success, error) {
+export function loginByLdap(teamName, id, password, token, success, error) {
     $.ajax({
         url: '/api/v1/users/login_ldap',
         dataType: 'json',
         contentType: 'application/json',
         type: 'POST',
-        data: JSON.stringify({teamName, id, password}),
+        data: JSON.stringify({teamName, id, password, token}),
         success: function onSuccess(data, textStatus, xhr) {
             track('api', 'api_users_loginLdap_success', data.team_id, 'id', id);
             sessionStorage.removeItem(data.id + '_last_error');
@@ -1712,3 +1727,18 @@ export function resendVerification(success, error, teamName, email) {
         }
     });
 }
+
+export function updateMfa(data, success, error) {
+    $.ajax({
+        url: '/api/v1/users/update_mfa',
+        dataType: 'json',
+        contentType: 'application/json',
+        type: 'POST',
+        data: JSON.stringify(data),
+        success,
+        error: (xhr, status, err) => {
+            var e = handleError('updateMfa', xhr, status, err);
+            error(e);
+        }
+    });
+}
-- 
cgit v1.2.3-1-g7c22

