Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] LoginRequestJson model)
        {
            var request = new LoginRequest(model);
            var result  = await _mediator.Send(request);

            return(StatusCode(result.Code, result.Description));
        }
    void loginGame()
    {
        warning.text = "";

        InputField usernameField = GameObject.Find("UsernameInputField").GetComponent <InputField>();
        InputField passwordField = GameObject.Find("PasswordInputField").GetComponent <InputField>();

        string username = usernameField.text;
        string password = passwordField.text;

        if (username == "")
        {
            warning.text = "username cannot be empty";
        }

        if (password == "")
        {
            warning.text = "password cannot be empty";
        }

        if (username != "" && password != "")
        {
            AmqpController.amqpControl.exchangeSubscription.Handler = ProcessLogin;

            LoginRequestJson loginRequest = new LoginRequestJson();
            loginRequest.id       = id;
            loginRequest.type     = "login";
            loginRequest.username = username;
            loginRequest.password = password;

            string request = JsonUtility.ToJson(loginRequest);
            AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, request);
        }
    }
Ejemplo n.º 3
0
        static private void DecodeLoginRequest(IConfiguration configuration, ref LoginRequestJson loginRequest, string token, string version, string connectionString)
        {
            string secret = DecyptString(configuration["JWTSecretEncypted"]);

            var json = new JwtBuilder()
                       .WithAlgorithm(new HMACSHA256Algorithm()) // symmetric
                       .WithSecret(secret)
                       .MustVerifySignature()
                       .Decode(token);
            JWTDesObect desObject = JsonConvert.DeserializeObject <JWTDesObect>(json);

            if (desObject == null || desObject.LoginRequest == null)
            {
                throw new Exception("Not valid");
            }

            if (desObject.LoginRequest.version != version)
            {
                throw new Exception("Invalid app version! Log off and log back again");
            }

            loginRequest = desObject.LoginRequest;
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                return;
            }
        }
Ejemplo n.º 4
0
        static public string DecodeConnectionString(IConfiguration configuration, ref LoginRequestJson loginRequest, string token, string version)
        {
            //string dbServer = configuration["DBServer"];
            //string dbName = configuration["DBName"];
            bool   isEncrypted      = Convert.ToBoolean(configuration["ConnectionStrings:Encrypted"]);
            string connectionString = configuration["ConnectionStrings:ConnStr"];

            if (isEncrypted == true)
            {
                connectionString = DecyptString(connectionString);
            }
            if (!string.IsNullOrWhiteSpace(token) && token != "null")
            {
                DecodeLoginRequest(configuration, ref loginRequest, token, version, connectionString);
            }


            return(connectionString);
            //return $"Data Source={dbServer};Initial Catalog={dbName};Persist Security Info=True;User ID={loginRequest.username};Password={loginRequest.password};TrustServerCertificate=true;";
        }
    void LoginGame()
    {
        warning.text = "";

        InputField usernameField = GameObject.Find("InputField_username").GetComponent <InputField>();
        InputField passwordField = GameObject.Find("InputField_password").GetComponent <InputField>();

        string username = usernameField.text;
        string password = passwordField.text;

        if (username == "")
        {
            warning.text = "username cannot be empty";
        }

        if (password == "")
        {
            warning.text = "password cannot be empty";
        }

        Debug.Log(username + " & " + password);

        if (username != "" && password != "")
        {
            AmqpControllerScript.amqpControl.exchangeSubscription.Handler = ProcessLogin;

            LoginRequestJson request = new LoginRequestJson();
            request.id       = id;
            request.type     = "login";
            request.username = username;
            request.password = password;

            string requestToJson = JsonUtility.ToJson(request);
            AmqpClient.Publish(AmqpControllerScript.amqpControl.requestExchange, AmqpControllerScript.amqpControl.requestRoutingKey, requestToJson);
        }
    }
 public HealthClaimReviewListController(ILogger <HealthClaimReviewListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 7
0
 public ClientOrgListController(ILogger <ClientOrgListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 8
0
        public async Task <JsonResult> Login()
        {
            LoginRequestJson  reqObj  = new LoginRequestJson();
            LoginResponseJson respObj = new LoginResponseJson()
            {
                success = false,
                message = "",
                code    = 0,
                token   = string.Empty
            };


            try
            {
                //Request.Headers["Authorization"]
                string bearer = Request.Headers["Authorization"];
                if (Request == null || Request.Headers == null || Request.Headers.Count == 0 || string.IsNullOrWhiteSpace(Request.Headers["Authorization"]) == true)
                {
                    Response.StatusCode = StatusCodes.Status401Unauthorized;
                    object respojseObj_MissingBearer = new
                    {
                        success = false,
                        message = "Authorization header is not provided",
                        code    = -401,
                        token   = ""
                    };
                    return(new JsonResult(respojseObj_MissingBearer));
                }
                string[] bearers = bearer.Split("Bearer ");
                if (bearers == null || bearers.Length != 2)
                {
                    Response.StatusCode = StatusCodes.Status401Unauthorized;
                    object respojseObj_MissingBearer = new
                    {
                        success = false,
                        message = "Missing bearer token",
                        code    = -401,
                        token   = ""
                    };
                    return(new JsonResult(respojseObj_MissingBearer));
                }

                using (var reader = new StreamReader(Request.Body))
                {
                    string body = string.Empty;
                    body = await reader.ReadToEndAsync();

                    dynamic jbody = JsonConvert.DeserializeObject(body);

                    if (jbody == null)
                    {
                        object respojseObj_MissingBearer = new
                        {
                            success = false,
                            message = "Missing request body",
                            code    = -401,
                            token   = ""
                        };
                        return(new JsonResult(respojseObj_MissingBearer));
                    }

                    foreach (dynamic item in jbody)
                    {
                        //int rowCount = 0;
                        //foreach (dynamic col in rows)
                        {
                            string name = item.Name;
                            string val  = item.Value.ToString();
                            switch (name)
                            {
                            case  "username":
                                reqObj.username = val;
                                break;

                            case "password":
                                reqObj.password = val;
                                break;
                            }
                        }
                    }
                }

                if (reqObj == null || string.IsNullOrWhiteSpace(reqObj.username) == true || string.IsNullOrWhiteSpace(reqObj.password))
                {
                    Response.StatusCode = StatusCodes.Status401Unauthorized;
                    object respojseObj_MissingBearer = new
                    {
                        success = false,
                        message = "No credentials provided",
                        code    = -401,
                        token   = ""
                    };
                    return(new JsonResult(respojseObj_MissingBearer));
                }

                reqObj.apiKey = bearers[1];
                dbCheckAPIKey(ref reqObj, ref respObj);
                dbIssueSessionToken(ref reqObj, ref respObj);
            }
            catch (Exception ex)
            {
                GIxUtils.Log(ex);
                Response.StatusCode = StatusCodes.Status401Unauthorized;
                object respojseObj_CheckBearer = new
                {
                    success = false,
                    message = $"{ex.Message}",
                    code    = -401,
                    token   = ""
                };
                return(new JsonResult(respojseObj_CheckBearer));
            }


            return(new JsonResult(respObj));
        }
Ejemplo n.º 9
0
 public CitizenshipListController(ILogger <CitizenshipListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
 public ReestrContractListController(ILogger <ReestrContractListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 11
0
        private bool dbIssueSessionToken(ref LoginRequestJson req, ref LoginResponseJson resp)
        {
            try
            {
                string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
                string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();
                //string passwordEncr = GIxUtils.EncryptString(req.password);

                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_IssueSessionToken]";
                        sqlCommand.Parameters.AddWithValue("@APIKey", req.apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Username", req.username);
                        sqlCommand.Parameters.AddWithValue("@Password", req.password);

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("IsOk")]) != System.DBNull.Value)
                                {
                                    resp.success = (bool)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("UniqueID")]) != System.DBNull.Value)
                                {
                                    req.salt = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("UserWho")]) != System.DBNull.Value)
                                {
                                    resp.userWho = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Email")]) != System.DBNull.Value)
                                {
                                    resp.email = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Avatar")]) != System.DBNull.Value)
                                {
                                    resp.avatar = (string)value;
                                }
                                if ((value = recordSet[recordSet.GetOrdinal("Version")]) != System.DBNull.Value)
                                {
                                    resp.version = (string)value;
                                }
                                resp.user   = _loginRequest.username;
                                req.version = resp.version;
                            }
                            recordSet.Close();
                            recordSet.Dispose();
                        }
                    }

                    /////
                    /// JWT Base64 user credentials as sessionvarialbelHas + guid from DB

                    var token = new JwtBuilder()
                                .WithAlgorithm(new HMACSHA256Algorithm())                              // symmetric
                                .WithSecret(GIxUtils.DecyptString(_configuration["JWTSecretEncypted"]))
                                .AddClaim("exp", DateTimeOffset.UtcNow.AddDays(1).ToUnixTimeSeconds()) //
                                .AddClaim("LoginRequest", req)
                                .Encode();

                    //Console.WriteLine(token);
                    resp.token = token;

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            if (!resp.success)
            {
                throw new Exception("პაროლი ან მომხმარებლის სახელი არასწორად არის შეყვანილი.");
            }
            return(resp.success);
        }
 public AgentBrokerListController(ILogger <AgentBrokerListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 13
0
 public LeftMenuListController(ILogger <LeftMenuListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 14
0
 public DashboardListController(ILogger <DashboardListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 15
0
 public HealthGuarantyLetterListController(ILogger <HealthGuarantyLetterListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 16
0
 public GadazgvevaListController(ILogger <GadazgvevaListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
 public UserPermissionListController(ILogger <UserPermissionListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 18
0
 public LoginRequest(LoginRequestJson loginRequestJson)
 {
     LoginRequestJson = loginRequestJson;
 }
Ejemplo n.º 19
0
 public PositionListController(ILogger <PositionListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 20
0
 public AutoPolicyListController(ILogger <AutoPolicyListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 21
0
 public SignatureListController(ILogger <SignatureListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
 public TravelClaimListController(ILogger <TravelClaimListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 23
0
 public CallCenterDocListController(ILogger <CallCenterDocListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 24
0
 public LoginController(ILogger <LoginController> logger, IConfiguration configuration /*, IHttpContextAccessor accessor*/)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 25
0
 public DepartmentListController(ILogger <DepartmentListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
Ejemplo n.º 26
0
        private bool dbCheckAPIKey(ref LoginRequestJson req, ref LoginResponseJson resp)
        {
            bool rezult = false;

            try
            {
                string remoteIP = this.HttpContext.Connection.RemoteIpAddress.ToString();
                string localIP  = this.HttpContext.Connection.LocalIpAddress.ToString();
                //string localHost = HttpContext.Features.Get()?.RemoteIpAddress?.ToString();
                //var a = HttpContext.Features.Get();

                using (SqlConnection sqlConnection = new SqlConnection(
                           GIxUtils.DecodeConnectionString(
                               _configuration,
                               ref _loginRequest,
                               Request.Headers["X-WebGI-Authentication"],
                               Request.Headers["X-WebGI-Version"])))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                    {
                        sqlCommand.Connection  = sqlConnection;
                        sqlCommand.CommandType = CommandType.StoredProcedure;
                        sqlCommand.CommandText = "dbo.[usp_WebGI_ChekAPIKey]";
                        sqlCommand.Parameters.AddWithValue("@APIKey", req.apiKey);
                        sqlCommand.Parameters.AddWithValue("@IP_Local", localIP);
                        sqlCommand.Parameters.AddWithValue("@IP_Remote", remoteIP);
                        sqlCommand.Parameters.AddWithValue("@Username", req.username);
                        //sqlCommand.Parameters.AddWithValue("@Salt", _loginRequest.salt);
                        //sqlCommand.Parameters.AddWithValue("@Version", _loginRequest.version);

                        SqlDataReader recordSet = sqlCommand.ExecuteReader();
                        using (recordSet)
                        {
                            object value;
                            if (recordSet.Read())
                            {
                                if ((value = recordSet[recordSet.GetOrdinal("IsOk")]) != System.DBNull.Value)
                                {
                                    rezult = (bool)value;
                                }
                            }
                            recordSet.Close();
                            recordSet.Dispose();
                        }
                    }

                    sqlConnection.Close();
                    sqlConnection.Dispose();
                }
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            if (!rezult)
            {
                throw new Exception("ავტორიზაციის შეცდომა! Invalid access token.");
            }
            return(rezult);
        }
Ejemplo n.º 27
0
 public TaskController(ILogger <TaskController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }
 public ExchangeRateListController(ILogger <ExchangeRateListController> logger, IConfiguration configuration)
 {
     _logger        = logger;
     _configuration = configuration;
     _loginRequest  = new LoginRequestJson();
 }