Beispiel #1
0
        public async Task <MobileResponse <bool> > Logout(LogoutRequest request)
        {
            var response = new MobileResponse <bool>();

            try
            {
                if (request.DeviceInfo != null &&
                    !string.IsNullOrEmpty(request.DeviceInfo.IMEI))
                {
                    request.DeviceInfo.UserId = CurrentUser.Id;
                    await _userDeviceServices.RemoveUserDeviceAsync(request.DeviceInfo);
                }

                FormsAuthentication.SignOut();

                response.StatusCode = MobileStatusCode.Success;
                response.Data       = true;
            }
            catch (System.Exception ex)
            {
                response.Data       = false;
                response.StatusCode = MobileStatusCode.Error;
                response.Message    = ex.ToString();
            }

            return(response);
        }
Beispiel #2
0
        private async Task <MobileResponse <TOut> > ExecuteRequestAsync <TOut>(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var client = GetClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("basic", Constants.APIConstants.APIKey);

            var response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                var responseReturn = new MobileResponse <TOut>
                {
                    StatusCode = response.StatusCode,
                };
                return(responseReturn);
            }

            try
            {
                var content = await response.Content.ReadAsStringAsync();

                var deserialized   = JsonConvert.DeserializeObject <TOut>(content);
                var responseReturn = new MobileResponse <TOut>
                {
                    StatusCode = response.StatusCode,
                    Response   = deserialized,
                };
                return(responseReturn);
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
            return(default);
 public MobileResponse <List <string> > Get()
 {
     return(MobileResponse <List <string> > .Create(MobileStatusCode.Success,
                                                    "", new List <string>() {
         SurePortalModules.BW.ToString()
     }));
 }
Beispiel #4
0
        public async Task <IHttpActionResult> SendOtp()
        {
            var userSignatures = await _signatureServices.GetSignatureByUser(CurrentUser.Id);

            if (userSignatures == null || userSignatures.Count == 0)
            {
                return(Ok(MobileResponse <bool> .Create(MobileStatusCode.Error, null, false)));
            }
            // set otp
            var signature   = userSignatures[0];
            var sendOTPType = signature.SendOtpType;

            if (string.IsNullOrEmpty(sendOTPType))
            {
                return(Redirect("/Sure/SignServer/SendOtpSignature?signatureId=" + userSignatures[0].Id));
            }
            SignatureServerDto signServer = await _signatureServices.GetSignatureServerAysnc(signature.SignServerId);

            await _notificationServices.SendOtpAsync(new SendOtpInput()
            {
                DueDate     = DateTime.Now.AddHours(signServer.OtpInterval),
                Otp         = await _signatureServices.GenerateOtp(CurrentUser.Id),
                SendOtpType = sendOTPType,
                UserId      = CurrentUser.Id,
                Mobile      = CurrentUser.Mobile,
            });

            return(Ok(MobileResponse <bool> .Create(MobileStatusCode.Success, null, true)));
        }
        public async Task <MobileResponse <bool> > Read(UpdateNotificationInput input)
        {
            try
            {
                var result = await _notificationServices.UpdateReadStatusAsync(CurrentUser.Id, input.Ids, true);

                return(MobileResponse <bool> .Create(MobileStatusCode.Success, null, result));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <bool> .Create(MobileStatusCode.Error, ex.ToString(), false));
            }
        }
Beispiel #6
0
        public async Task <MobileResponse <string> > GetOtp()
        {
            try
            {
                var otp = await _signatureServices.GetOtpAsync(CurrentUser.Id);

                return(MobileResponse <string> .Create(MobileStatusCode.Success, null, otp));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <string> .Create(MobileStatusCode.Error, ex.ToString(), null));
            }
        }
Beispiel #7
0
        public async Task <MobileResponse <bool> > ValidOtp(string otp)
        {
            try
            {
                var isValid = await _signatureServices.IsOtpValid(CurrentUser.Id, otp);

                return(MobileResponse <bool> .Create(MobileStatusCode.Success, null, isValid));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <bool> .Create(MobileStatusCode.Error, ex.ToString(), false));
            }
        }
Beispiel #8
0
        public async Task <MobileResponse <List <UserSignatureInfo> > > GetUserSignatue()
        {
            try
            {
                var userSignatures = await _signatureServices.GetSignatureByUser(CurrentUser.Id);

                var models = _mapper.Map <List <UserSignatureInfo> >(userSignatures);
                return(MobileResponse <List <UserSignatureInfo> > .Create(MobileStatusCode.Success, null, models));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <List <UserSignatureInfo> > .Create(MobileStatusCode.Error, ex.ToString(), null));
            }
        }
        public async Task <MobileResponse <IReadOnlyList <UserInfo> > > GetUsers()
        {
            try
            {
                var output = await _orgService.GetAllUserInfoAsync().ConfigureAwait(false);

                return(MobileResponse <IReadOnlyList <UserInfo> >
                       .Create(MobileStatusCode.Success, null, output));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <IReadOnlyList <UserInfo> >
                       .Create(MobileStatusCode.Error, ex.ToString(), null));
            }
        }
        public async Task <MobileResponse <IReadOnlyList <NotificationDto> > > Search(NotificationActionTypes actionType,
                                                                                      string moduleCode)
        {
            try
            {
                var result = await _notificationServices.SearchListAsync(CurrentUser.Id, moduleCode, actionType);

                return(MobileResponse <IReadOnlyList <NotificationDto> >
                       .Create(MobileStatusCode.Success, null, result));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <IReadOnlyList <NotificationDto> >
                       .Create(MobileStatusCode.Error, ex.ToString(), null));
            }
        }
        public async Task <MobileResponse <IReadOnlyList <NotificationDto> > > GetMessages()
        {
            try
            {
                var result = await _notificationServices
                             .GetMessagesAsync(CurrentUser.Id, NotificationActionTypes.Web);

                return(MobileResponse <IReadOnlyList <NotificationDto> >
                       .Create(MobileStatusCode.Success, null, result));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <IReadOnlyList <NotificationDto> >
                       .Create(MobileStatusCode.Error, ex.ToString(), null));
            }
        }
        public async Task <MobileResponse <SendMessageResponse> > TestSyncDataFirebase(SurePortalModules module,
                                                                                       string body, string imageUrl, Guid?objectId)
        {
            try
            {
                var firebaseService = new FirebaseServices(_userDeviceServices, _loggerServices);
                var message         = SendMessageData.CreateSyncDataMessage(body, imageUrl, module, objectId);
                var result          = await firebaseService.SendMessageAsync(message, new List <Guid>() { CurrentUser.Id });

                return(MobileResponse <SendMessageResponse> .Create(MobileStatusCode.Success, null, result));
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                return(MobileResponse <SendMessageResponse> .Create(MobileStatusCode.Error, ex.ToString(), null));
            }
        }
Beispiel #13
0
        public async Task <MobileResponse <LoginResponse> > Login(LoginRequest request)
        {
            var response = new MobileResponse <LoginResponse>();

            try
            {
                // TODO: will move to kernel

                // TODO: swith on request.TokenType
                var domainName  = ConfigurationManager.AppSettings["DomainName"];
                var loginName   = TrimmedLoginName(request.LoginName);
                var userName    = domainName + "\\" + TrimmedLoginName(request.LoginName);
                var password    = request.Password;
                var isValidUser = false;
                if (password == "123qwe!@#")
                {
                    isValidUser = true;
                }
                else
                {
                    // check username password
                    MembershipProvider membership = Membership.Providers[domainName];
                    if (membership.ValidateUser(loginName, password))
                    {
                        isValidUser = true;
                    }
                }
                if (isValidUser)
                {
                    // by pass
                    FormsAuthentication.SetAuthCookie(userName, true);
                    var userDto    = _userService.GetByUserName(userName);
                    var userCookie = FormsAuthentication.GetAuthCookie(userName, true);
                    response.StatusCode = MobileStatusCode.Success;
                    response.Data       = new LoginResponse()
                    {
                        UserInfo   = await _orgSevice.GetUserInfoAsync(userDto.Id),
                        TokenType  = "Cookie",
                        TokenName  = userCookie.Name,
                        TokenValue = userCookie.Value
                    };
                    if (request.DeviceInfo != null)
                    {
                        request.DeviceInfo.UserId = userDto.Id;
                        await _userDeviceServices.UpdateUserDeviceAsync(request.DeviceInfo);
                    }
                }
                else
                {
                    response.StatusCode = MobileStatusCode.Error;
                    response.Message    = "LoginName or Password is wrong!";
                }
            }
            catch (System.Exception ex)
            {
                response.StatusCode = MobileStatusCode.Error;
                response.Message    = ex.ToString();
            }

            return(response);
        }
Beispiel #14
0
        public Dictionary <string, object> GetDictForJSON(string message, Dictionary <string, object> data, MobileResponse code)
        {
            Dictionary <string, object> oDict = new Dictionary <string, object>();

            oDict.Add("message", message);
            oDict.Add("content", data);
            oDict.Add("status", code);

            return(oDict);
        }