Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ApiAuthResponse AuthResponseObj = new ApiAuthResponse();

        try
        {
            UserProfile UserProfileObj          = new UserProfile(Token: CookieProxy.Instance().GetValue("t").ToString(), Email: Request.Form["e"].ToString());
            UserTemplate <IUserProfile> Profile = new AdminUserTemplate(UserProfileObj);
            APIResponse Response = Profile.Remove();
            AuthResponseObj.SetAPIResponse(Response);
            if (Response == APIResponse.NOT_AUTHENTICATED)
            {
                CookieProxy.Instance().SetValue("LoginMessage", "Unable to authenticate the token, please relogin or relogin", DateTime.Now.AddDays(2));
            }

            if (AuthResponseObj.GetAPIResponse() == APIResponse.OK)
            {
                // log the event
                Logger.Instance().Log(Info.Instance(), new LogInfo(new AdminUserTemplate().FetchParticularProfile(UserProfileObj).GetEmail() + " removed " + Request.Form["e"]));
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Info.Instance(), ex);
        }
        finally
        {
            Response.Write(new JavaScriptSerializer().Serialize(AuthResponseObj));
        }
    }
Exemple #2
0
        public async Task UpdateAuthInfo(ApiAuthResponse resp, string username)
        {
            try
            {
                await Store.SetValueAsync(AppConst.BTOKEN, resp.BToken);

                await Store.SetValueAsync(AppConst.RTOKEN, resp.RToken);

                App.Settings.RToken      = resp.RToken;
                App.Settings.BToken      = resp.BToken;
                App.Settings.CurrentUser = resp.User;

                await Store.SetJSONAsync(AppConst.USER_OBJECT, resp.User);

                if (resp.DisplayPicture != null)
                {
                    INativeHelper helper = DependencyService.Get <INativeHelper>();

                    string url = helper.NativeRoot + $"/{App.Settings.AppDirectory}/{ App.Settings.Sid.ToUpper()}/user.png";
                    File.WriteAllBytes(url, resp.DisplayPicture);
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("UpdateAuthInfo---" + ex.Message);
            }
        }
        public void ShowTwoFAWindow(ApiAuthResponse auth)
        {
            TwoFAWindow.SetAddress(auth.TwoFAToAddress);

            TwoFAWindow.Show();
            RestButton.IsVisible = false;
        }
Exemple #4
0
        public async Task <ApiAuthResponse> AuthenticateSSOAsync(string username, string authid, string token)
        {
            ApiAuthResponse resp;

            try
            {
                RestRequest request = new RestRequest(ApiConstants.AUTHETICATE_SSO, Method.GET);

                request.AddParameter("username", username.Trim().ToLower());
                request.AddParameter("authid", authid);
                request.AddParameter("token", token);

                IRestResponse response = await HttpClient.ExecuteAsync(request);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    resp = JsonConvert.DeserializeObject <ApiAuthResponse>(response.Content);
                }
                else
                {
                    resp = new ApiAuthResponse {
                        IsValid = false
                    }
                };
            }
            catch (Exception ex)
            {
                EbLog.Error(ex.Message);
                resp = new ApiAuthResponse {
                    IsValid = false
                };
            }
            return(resp);
        }
Exemple #5
0
        public async Task <ApiGenerateOTPResponse> GenerateOTP(ApiAuthResponse autheresp)
        {
            RestRequest request = new RestRequest(ApiConstants.RESEND_OTP, Method.POST);

            if (!string.IsNullOrEmpty(autheresp.BToken))
            {
                request.AddHeader(AppConst.BTOKEN, autheresp.BToken);
                request.AddHeader(AppConst.RTOKEN, autheresp.RToken);
            }

            request.AddParameter("token", autheresp.TwoFAToken);
            request.AddParameter("authid", autheresp.User.AuthId);

            try
            {
                IRestResponse response = await HttpClient.ExecuteAsync(request);

                if (response.IsSuccessful)
                {
                    return(JsonConvert.DeserializeObject <ApiGenerateOTPResponse>(response.Content));
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("2FA verification failed :: " + ex.Message);
            }
            return(null);
        }
Exemple #6
0
        public async Task <ApiAuthResponse> SendAuthenticationOTP(string username, SignInOtpType type)
        {
            ApiAuthResponse resp;

            RestRequest request = new RestRequest(ApiConstants.SEND_AUTH_OTP, Method.POST);

            request.AddParameter("username", username);
            request.AddParameter("type", (int)type);

            try
            {
                IRestResponse response = await HttpClient.ExecuteAsync(request);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    resp = JsonConvert.DeserializeObject <ApiAuthResponse>(response.Content);
                }
                else
                {
                    resp = new ApiAuthResponse {
                        IsValid = false
                    }
                };
            }
            catch (Exception ex)
            {
                EbLog.Error("AuthenticateSSOAsync failed :: " + ex.Message);
                resp = new ApiAuthResponse {
                    IsValid = false
                };
            }
            return(resp);
        }
Exemple #7
0
        protected async Task AfterLoginSuccess(ApiAuthResponse resp, string username, LoginType loginType, Loader loader)
        {
            try
            {
                await Service.UpdateAuthInfo(resp, username);

                await Service.UpdateLastUser(username, loginType);

                EbMobileSolutionData data = await App.Settings.GetSolutionDataAsync(loader);

                IsBusy = true;

                if (App.Settings.Vendor.AllowNotifications)
                {
                    await NotificationService.Instance.UpdateNHRegistration();
                }

                if (data != null)
                {
                    await Service.Navigate(data);
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("Exception at after login :: " + ex.Message);
            }
        }
Exemple #8
0
        public async Task <ApiAuthResponse> AuthenticateAsync(string username, string password, bool anonymous = false)
        {
            ApiAuthResponse resp;

            try
            {
                RestRequest request = new RestRequest(ApiConstants.AUTHETICATE, Method.GET);

                request.AddParameter("username", username.Trim().ToLower());
                request.AddParameter("password", string.Concat(password, username).ToMD5());
                INativeHelper helper = DependencyService.Get <INativeHelper>();
                request.AddParameter("deviceid", helper.DeviceId);

                if (anonymous)
                {
                    request.AddParameter("anonymous", true);
                }

                IRestResponse response = await HttpClient.ExecuteAsync(request);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    resp = JsonConvert.DeserializeObject <ApiAuthResponse>(response.Content);
                }
                else
                {
                    resp = new ApiAuthResponse {
                        IsValid = false, Message = "Auth failed: " + response.ErrorMessage
                    }
                };
            }
            catch (Exception ex)
            {
                EbLog.Error(ex.Message);
                resp = new ApiAuthResponse {
                    IsValid = false, Message = "Auth failed: " + ex.Message
                };
            }
            return(resp);
        }
Exemple #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ApiAuthResponse AuthResponseObj = new ApiAuthResponse();

        try
        {
            UserProfile UserProfileObj          = new UserProfile(Token: CookieProxy.Instance().GetValue("t").ToString(), Email: Request.Form["e"].ToString());
            UserTemplate <IUserProfile> Profile = new AdminUserTemplate(UserProfileObj);
            APIResponse ResponseObj             = Profile.Add();
            AuthResponseObj.SetAPIResponse(ResponseObj);
            if (ResponseObj == APIResponse.OK)
            {
                // log the event
                Logger.Instance().Log(Info.Instance(), new LogInfo(Profile.FetchParticularProfile(UserProfileObj).GetEmail() + " added " + Request.Form["e"]));
            }
        }
        catch (Exception ex)
        {
            AuthResponseObj.SetAPIResponse(APIResponse.NOT_OK);
            Logger.Instance().Log(Fatal.Instance(), ex);
        }
        Response.Write(new JavaScriptSerializer().Serialize(AuthResponseObj));
    }
Exemple #10
0
 public void ShowTwoFAWindow(ApiAuthResponse auth)
 {
     TwoFAWindow.SetAddress(auth.TwoFAToAddress);
     TwoFAWindow.Show();
 }