Exemplo n.º 1
0
        public LoginResponsee Logindata(Login ul)
        {
            LoginResponsee res = new LoginResponsee();

            try
            {
                SqlConnection con      = new SqlConnection(ConfigurationManager.ConnectionStrings[Convert.ToString(ul.AppId)].ConnectionString);
                string        Message  = "";
                string        userId   = "";
                string        Username = "";

                con.Open();
                string query = "Sp_WebSevice";

                SqlCommand cmd = new SqlCommand(query, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@QueryType", "GetUser");
                cmd.Parameters.AddWithValue("@UserName", ul.emailId);


                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet        dt = new DataSet();
                da.Fill(dt);

                // bool isFound = false;

                int i = 0;
                if (dt != null)
                {
                    foreach (DataRow row in dt.Tables[0].Rows)
                    {
                        string pin   = dt.Tables[0].Rows[i]["UserName"].ToString();
                        string Passw = DBsecurity.Decrypt(dt.Tables[0].Rows[i]["Password"].ToString(), dt.Tables[0].Rows[i]["PasswordKey"].ToString());
                        if (Passw == ul.password.Trim())
                        {
                            Username     = Convert.ToString(dt.Tables[0].Rows[i]["UserName"]);
                            res.userName = Username;
                            userId       = Convert.ToString(dt.Tables[0].Rows[i]["UserId"]);
                            res.userId   = userId;
                            Message      = "Login successfully";
                            res.message  = Message;
                            res.status   = "success";
                            break;
                        }
                        else
                        {
                            res.status = "failure";
                            Message    = "Invalid Credentials";
                        }
                        i++;
                    }
                }
                else
                {
                    res.status   = "failure";
                    res.message  = "Invalid Credentials";
                    res.userName = "";
                    res.userId   = "";
                }


                con.Close();
            }

            catch (Exception ex)
            {
                res.status  = "server error";
                res.message = "Invalid data";
            }
            return(res);
        }
Exemplo n.º 2
0
        public UserLogin Login(UserLoginRequest ul)
        {
            if (ul.UserPin.Trim() != "" && Validation.ValidateUserPin(ul.UserPin.Trim()) != true)
            {
                res.Message           = "UserPin Must be 4 digit";
                res.Status            = "Failure";
                res.UserLoginResponse = ListView;
                Ulr.UserId            = "";
                Ulr.UserPin           = "";
                ListView.Add(Ulr);
                return(res);
            }

            else
            {
                //bool Flag = true;

                try
                {
                    query     = "SP_LoginWebApi";
                    dbcommand = new SqlCommand(query, conn);
                    dbcommand.Connection.Open();
                    dbcommand.CommandType = CommandType.StoredProcedure;
                    dbcommand.Parameters.AddWithValue("@QueryType", "UserAccess");
                    dbcommand.Parameters.AddWithValue("@UserPin", ul.UserPin);
                    SqlDataAdapter da = new SqlDataAdapter(dbcommand);
                    DataSet        ds = new DataSet();
                    da.Fill(ds);

                    if (ul.UserPin.Trim() != "" && ul.Password != "")
                    {
                        //if (Convert.ToString(ds.Tables[0].Rows[0]["UserPin"]) == "0")
                        //{

                        //    res.Message = "User has been disabled, please contact administrator!";
                        //    res.Status = "Failure";
                        //    res.UserLoginResponse = ListView;
                        //    Ulr.UserId = "";
                        //    Ulr.UserPin = "";
                        //    ListView.Add(Ulr);
                        //    return res;

                        //}
                        //else if (Convert.ToString(ds.Tables[0].Rows[0]["UserPin"]) == "-1")
                        //{

                        //    res.Message = "Invalid User Pin!";
                        //    res.Status = "Failure";
                        //    res.UserLoginResponse = ListView;
                        //    Ulr.UserId = "";
                        //    Ulr.UserPin = "";
                        //    ListView.Add(Ulr);
                        //    return res;

                        //}
                        //else
                        //{

                        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            //bool IsLoginfirsttime = Convert.ToBoolean(ds.Tables[0].Rows[0]["LoginFlag"]);
                            string UserType = Convert.ToString(ds.Tables[0].Rows[0]["UserRoleID"]);

                            if (UserType == "1")
                            {
                                #region For Admin
                                string strDbPassword = DBsecurity.Decrypt(Convert.ToString(ds.Tables[0].Rows[0]["Password"]), Convert.ToString(ds.Tables[0].Rows[0]["PasswordKey"]));
                                if (strDbPassword.Trim() != ul.Password.Trim())
                                {
                                    res.Message           = "Wrong Password.";
                                    res.Status            = "Failure";
                                    res.UserLoginResponse = ListView;
                                    Ulr.UserPin           = "";
                                    Ulr.UserId            = "";
                                    ListView.Add(Ulr);
                                    return(res);
                                }
                                //
                                else
                                {
                                    res.Message           = "Valid User.";
                                    res.Status            = "success";
                                    res.UserLoginResponse = ListView;
                                    Ulr.UserId            = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]);
                                    Ulr.UserPin           = "";
                                    ListView.Add(Ulr);
                                    return(res);
                                }
                                #endregion
                            }
                            else
                            {
                                //if (IsLoginfirsttime == true)
                                //{
                                //    #region For First Time User Login
                                //    string strDbPassword = DBsecurity.Decrypt(Convert.ToString(ds.Tables[0].Rows[0]["Password"]), Convert.ToString(ds.Tables[0].Rows[0]["PasswordKey"]));
                                //    if (strDbPassword.Trim() != ul.Password.Trim())
                                //    {


                                //        res.Message = "Wrong Password.";
                                //        res.Status = "Failure";
                                //        res.UserLoginResponse = ListView;
                                //        Ulr.UserId ="";
                                //        Ulr.UserPin = "";
                                //        ListView.Add(Ulr);
                                //        return res;
                                //    }
                                //    else
                                //    {
                                //        res.Message = "Valid User.";
                                //        res.Status = "success";
                                //        res.UserLoginResponse = ListView;
                                //        Ulr.UserId = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]);
                                //        Ulr.UserPin = "";
                                //        ListView.Add(Ulr);
                                //        return res;


                                //    }
                                //    #endregion
                                //}
                                //else
                                //{
                                #region For Current user
                                //if (Convert.ToString(ConfigurationManager.AppSettings["DefaultPassword"]) == ul.Password.Trim())
                                //{
                                res.Message      = "Valid User.";
                                res.Status       = "Success";
                                res.UserSiteInfo = UserMultipleSiteInfo;
                                foreach (DataRow row in ds.Tables[0].Rows)
                                {
                                    UserMultipleSiteInfo UserMultipleSite = new UserMultipleSiteInfo();
                                    UserMultipleSite.Site      = row["AXSiteId"].ToString();
                                    UserMultipleSite.WareHouse = row["WareHouseAX"].ToString();
                                    UserMultipleSiteInfo.Add(UserMultipleSite);
                                }
                                res.UserLoginResponse             = ListView;
                                Ulr.UserId                        = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]);
                                Ulr.UserPin                       = ul.UserPin;
                                Ulr.IsMove                        = Convert.ToByte(ds.Tables[0].Rows[0]["IsMove"]);
                                Ulr.IsReportAsFinished            = Convert.ToByte(ds.Tables[0].Rows[0]["IsReportAsFinished"]);
                                Ulr.IsQualityCheck                = Convert.ToByte(ds.Tables[0].Rows[0]["IsQualityCheck"]);
                                Ulr.IsAssignedPlannedAndUnplanned = Convert.ToByte(ds.Tables[0].Rows[0]["IsAssignedPlannedAndUnplanned"]);
                                Ulr.IsPickAndCount                = Convert.ToByte(ds.Tables[0].Rows[0]["IsPickAndCount"]);
                                Ulr.IsMergeStillage               = Convert.ToByte(ds.Tables[0].Rows[0]["IsMergeStillage"]);
                                Ulr.IsReturnStillage              = Convert.ToByte(ds.Tables[0].Rows[0]["IsReturnStillage"]);
                                Ulr.IsRecieveReturnStillage       = Convert.ToByte(ds.Tables[0].Rows[0]["IsRecieveReturnStillage"]);
                                Ulr.IsLookUp                      = Convert.ToByte(ds.Tables[0].Rows[0]["IsLookUp"]);
                                Ulr.IsUpdateQty                   = Convert.ToByte(ds.Tables[0].Rows[0]["IsUpdateQty"]);
                                Ulr.IsProductionJournal           = Convert.ToByte(ds.Tables[0].Rows[0]["IsProductionJournal"]);
                                Ulr.IsWorkOrderStartEnd           = Convert.ToByte(ds.Tables[0].Rows[0]["IsWorkOrderStartEnd"]);
                                Ulr.UserName                      = Convert.ToString(ds.Tables[0].Rows[0]["UserName"]);
                                Ulr.EmailId                       = Convert.ToString(ds.Tables[0].Rows[0]["EmailId"]);
                                ListView.Add(Ulr);
                                return(res);


                                //}
                                //else
                                //{

                                //    res.Message = "Wrong Password.";
                                //    res.Status = "Failure";
                                //    res.UserLoginResponse = ListView;
                                //    Ulr.UserId = "";
                                //    Ulr.UserPin = "";
                                //    ListView.Add(Ulr);
                                //    return res;


                                //}
                                #endregion
                                //}
                            }
                        }
                        else
                        {
                            res.Message           = "Invalid User.";
                            res.Status            = "Failure";
                            res.UserLoginResponse = ListView;
                            Ulr.UserId            = "";
                            Ulr.UserPin           = "";
                            ListView.Add(Ulr);
                            return(res);
                        }
                        // }
                    }
                    else
                    {
                        res.Message           = "Wrong User Pin or Password.";
                        res.Status            = "Failure";
                        res.UserLoginResponse = ListView;
                        Ulr.UserId            = "";
                        Ulr.UserPin           = "";
                        ListView.Add(Ulr);
                        return(res);
                    }
                }
                catch (Exception ex)
                {
                    res.Status  = "Failure";
                    res.Message = ex.Message;
                }
                finally
                {
                    dbcommand.Connection.Close();
                }


                return(res);
            }
        }