Ejemplo n.º 1
0
        private Task <ClaimsIdentity> GetIdentity(string Par_Username,
                                                  string Par_Password,
                                                  string Par_IPAddress,
                                                  string Par_MachineID,
                                                  WebApiUserTypesEnum ParWebApiUserType,
                                                  out string Par_Out_Result,
                                                  List <string> CallTrace)
        {
            Par_Out_Result = string.Empty;

            try
            {
                switch (ParWebApiUserType)
                {
                case WebApiUserTypesEnum.NotAuthorized:
                    if (Par_Username.Equals(GlobalData.NotAuthorizedUserName) && Par_Password.Equals(GlobalData.NotAuthorizedUserPass))
                    {
                        Par_Out_Result = Guid.Empty.ToString() + GlobalFunctions.GetRandomAlphaNumeric(10);
                        return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(Par_Username, "Token"), new Claim[] { })));
                    }
                    else
                    {
                        Par_Out_Result = "Invalid NotAutorizedUser UserName or Password";
                    }
                    break;

                case WebApiUserTypesEnum.Authorized:
                    CosmosDocUser cosmosDocUser = CosmosAPI.cosmosDBClientUser.FindUserByUserName(Par_Username, TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result;
                    if (cosmosDocUser != null)
                    {
                        if (LocalFunctions.CompareHash(Par_Password, cosmosDocUser, TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())))
                        {
                            Par_Out_Result = cosmosDocUser.ID.ToString() + GlobalFunctions.GetRandomAlphaNumeric(10);

                            return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(Par_Username, "Token"), new Claim[] { })));
                        }
                        else
                        {
                            Par_Out_Result = "Invalid User Password";
                        }
                    }
                    else
                    {
                        Par_Out_Result = "Invalid User Name";
                    }

                    break;

                case WebApiUserTypesEnum.Admin:

                    if (Par_IPAddress.Equals(GlobalData.AdminIPAddress))
                    {
                        if (Par_MachineID.Equals(GlobalData.AdminMachineID))
                        {
                            if (Par_Username.Equals(GlobalData.AdminUserName) && Par_Password.Equals(GlobalData.AdminUserPass))
                            {
                                Par_Out_Result = Guid.Empty.ToString() + GlobalFunctions.GetRandomAlphaNumeric(10);
                                return(Task.FromResult(new ClaimsIdentity(new System.Security.Principal.GenericIdentity(Par_Username, "Token"), new Claim[] { })));
                            }
                            else
                            {
                                Par_Out_Result = "Invalid Admin UserName or Password";
                            }
                        }
                        else
                        {
                            Par_Out_Result = "Invalid Admin MachineID";
                        }
                    }
                    else
                    {
                        Par_Out_Result = "Invalid Admin IPAddress";
                    }
                    break;

                default:
                    Par_Out_Result = "unknown error";
                    break;
                }
            }
            catch (Exception ex)
            {
                bool b = CosmosAPI.cosmosDBClientError.AddErrorLog(Guid.Empty, ex.Message, TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result;
            }

            return(Task.FromResult <ClaimsIdentity>(null));
        }