(String username, String password, String database, String serverURL)
| 107 | } |
| 108 | |
| 109 | public OEUser login(String username, String password, String database, |
| 110 | String serverURL) { |
| 111 | Log.d(TAG, "OEHelper->login()"); |
| 112 | OEUser userObj = null; |
| 113 | try { |
| 114 | mOdoo = new Odoo(serverURL, mAllowSelfSignedSSL); |
| 115 | JSONObject response = mOdoo.authenticate(username, password, |
| 116 | database); |
| 117 | int userId = 0; |
| 118 | if (response.get("uid") instanceof Integer) { |
| 119 | mApp.setOEInstance(mOdoo); |
| 120 | if (OEUser.current(mContext) == null || !withUser) { |
| 121 | userId = response.getInt("uid"); |
| 122 | |
| 123 | OEFieldsHelper fields = new OEFieldsHelper(new String[] { |
| 124 | "partner_id", "tz", "image", "company_id" }); |
| 125 | OEDomain domain = new OEDomain(); |
| 126 | domain.add("id", "=", userId); |
| 127 | JSONObject res = mOdoo |
| 128 | .search_read("res.users", fields.get(), |
| 129 | domain.get()).getJSONArray("records") |
| 130 | .getJSONObject(0); |
| 131 | |
| 132 | userObj = new OEUser(); |
| 133 | userObj.setAvatar(res.getString("image")); |
| 134 | |
| 135 | userObj.setDatabase(database); |
| 136 | userObj.setHost(serverURL); |
| 137 | userObj.setIsactive(true); |
| 138 | userObj.setAndroidName(androidName(username, database)); |
| 139 | userObj.setPartner_id(res.getJSONArray("partner_id") |
| 140 | .getInt(0)); |
| 141 | userObj.setTimezone(res.getString("tz")); |
| 142 | userObj.setUser_id(userId); |
| 143 | userObj.setUsername(username); |
| 144 | userObj.setPassword(password); |
| 145 | userObj.setAllowSelfSignedSSL(mAllowSelfSignedSSL); |
| 146 | String company_id = new JSONArray( |
| 147 | res.getString("company_id")).getString(0); |
| 148 | userObj.setCompany_id(company_id); |
| 149 | } else { |
| 150 | userObj = OEUser.current(mContext); |
| 151 | } |
| 152 | } |
| 153 | } catch (Exception e) { |
| 154 | e.printStackTrace(); |
| 155 | } |
| 156 | return userObj; |
| 157 | } |
| 158 | |
| 159 | public OEUser getUser() { |
| 160 | return mUser; |
no test coverage detected