Exemplo n.º 1
0
        public UserLogin ChangePassword(UserLoginRequest ul)
        {
            try
            {
                if (ul.UserPin.Trim() == "")
                {
                    res.Message           = "User cannot be blank";
                    res.Status            = "Failure";
                    res.UserLoginResponse = ListView;
                    Ulr.UserId            = "";
                    Ulr.UserPin           = "";
                    ListView.Add(Ulr);
                    return(res);
                }
                else
                {
                    if (ul.Password.Trim() != "")
                    {
                        string pass    = string.Empty;
                        string passkey = string.Empty;

                        pass = DBsecurity.Encrypt(ul.Password.Trim(), ref passkey);

                        query     = "SP_Login";
                        dbcommand = new SqlCommand(query, conn);
                        dbcommand.Connection.Open();
                        dbcommand.CommandType = CommandType.StoredProcedure;
                        dbcommand.Parameters.AddWithValue("@QueryType", "APIUpdatePassword");
                        dbcommand.Parameters.AddWithValue("@UserPin", ul.UserPin);
                        dbcommand.Parameters.AddWithValue("@Password", pass);
                        dbcommand.Parameters.AddWithValue("@PasswordKey", passkey);
                        SqlDataAdapter da = new SqlDataAdapter(dbcommand);
                        DataTable      dt = new DataTable();
                        da.Fill(dt);
                        conn.Close();



                        if (dt.Rows.Count > 0)
                        {
                            res.Message           = "Password has been changed";
                            res.Status            = "success";
                            res.UserLoginResponse = ListView;
                            Ulr.UserId            = "";
                            Ulr.UserPin           = "";
                            ListView.Add(Ulr);
                        }
                    }
                    else
                    {
                        res.Message           = "Password cannot be blank";
                        res.Status            = "Failure";
                        res.UserLoginResponse = ListView;
                        Ulr.UserId            = "";
                        Ulr.UserPin           = "";
                        ListView.Add(Ulr);
                    }
                }
            }
            catch (Exception ex)
            {
                res.Status  = "Failure";
                res.Message = ex.Message;
            }
            finally
            {
                dbcommand.Connection.Close();
            }
            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);
            }
        }