Esempio n. 1
0
        public dynamic ForgotPassword([FromBody] Newtonsoft.Json.Linq.JObject param)
        {
            dynamic obj         = param;
            var     LoginName   = obj.loginName; //HttpContext.Request.Form["formDataObj1"];
            var     accountType = obj.loginType; //HttpContext.Request.Form["formDataObj2"];

            var adminresult = (_repositoryWrapper.Admin.GetAdminByLoginName(LoginName.ToString()));

            //var aa=adminresult.ToList();
            if (adminresult.Count <= 0)
            {
                return(new { data = false });
            }
            else
            {
                string ToEmail      = adminresult[0].Email.ToString();
                string ID           = adminresult[0].AdminID.ToString();
                string Account_Name = adminresult[0].AdminName.ToString();
                string salt         = adminresult[0].Salt.ToString();
                string PWD          = "";

                var emailtemplateresult = (_repositoryWrapper.EmailTemplate.GetEmailTemplate("Forgot Password Notification")).ToList();

                string Message   = emailtemplateresult[0].template_content;
                string Subject   = emailtemplateresult[0].subject;
                string Variable  = emailtemplateresult[0].variable;
                string FromEmail = emailtemplateresult[0].from_email;

                var settingresult = (_repositoryWrapper.Setting.GetPasswordValidation()).ToList();
                var pwdlength     = settingresult[0].Value;
                var Password      = Operational.Cryptography.RandomPassword.Generate(int.Parse(pwdlength));

                if (Password != "" && Password.Length >= int.Parse(pwdlength))
                {
                    PWD = Operational.Encrypt.SaltedHash.ComputeHash(salt, Password);
                }

                var plainTextBytes = Encoding.UTF8.GetBytes(ID);
                ID = Convert.ToBase64String(plainTextBytes).Replace("=", "%3D");

                plainTextBytes = Encoding.UTF8.GetBytes(PWD);
                string enc_newpass = Convert.ToBase64String(plainTextBytes).Replace("=", "%3D");

                plainTextBytes = Encoding.UTF8.GetBytes(salt);
                string enc_salt = Convert.ToBase64String(plainTextBytes).Replace("=", "%3D");

                string reset_url = "#/forgotpassword/" + ID + "/" + enc_newpass + "/" + enc_salt;

                string body = Message.Replace("[Account Name]", Account_Name).Replace("[Account Email]", ToEmail).Replace("[Reset URL]", reset_url).Replace("[Generate Password]", Password).Replace("\n", "<br/>");

                var  settingResultList = _repositoryWrapper.Setting.GetEmailSetting().ToList();
                bool result            = Globalfunction.SendEmailAsync(settingResultList, ToEmail, FromEmail, Subject, body, true);
                // if(!isSuccess) _repositoryWrapper.EventLog.AddEventLog("Error", "Send Mail", ex.Message, "0", "0", "");
                return(result);
            }
        }
Esempio n. 2
0
        public string FileUpload()
        {
            //string filename = "";
            //string ext = "";

            /*     byte[] data = Convert.FromBase64String(fileparam);
             *  string decodedString = Encoding.UTF8.GetString(data);
             *  Char delimiter = '/';
             *  String[] substrings = decodedString.Split(delimiter);
             *  if (substrings.Length >= 1)
             *      filename = substrings[0];
             *  if (substrings.Length >= 2)
             *      ext = substrings[1]; */
            string returnStr = "Fail to Upload";

            try
            {
                var files = Request.Form.Files;
                if (files.Count > 0)
                {
                    var    appsettingbuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                    var    Configuration     = appsettingbuilder.Build();
                    string folderPath        = "";
                    string fullPath          = "";

                    /////////stockphoto/////////

                    folderPath = Configuration.GetSection("appSettings:uploadStockPath").Value;
                    fullPath   = folderPath + "pp" + "." + "png";

                    // Save the file
                    var file = files[0];
                    if (file.Length > 0)
                    {
                        using (var fileStream = new FileStream(fullPath, FileMode.OpenOrCreate))
                        {
                            file.CopyTo(fileStream);
                        }
                    }
                    Response.ContentType = "application/json";
                    returnStr            = "Succesfully Upload";
                }
            }
            catch (Exception ex)
            {
                returnStr = "Fail to Upload";
                Globalfunction.WriteSystemLog(ex.Message);
            }
            return(returnStr);
        }
Esempio n. 3
0
 public void setDefaultDataFromToken()
 {
     try
     {
         string access_token = "";
         var    hdtoken      = Request.Headers["Authorization"];
         if (hdtoken.Count > 0)
         {
             access_token = hdtoken[0];
             access_token = access_token.Replace("Bearer ", "");
             var handler = new JwtSecurityTokenHandler();
             var tokenS  = handler.ReadToken(access_token) as JwtSecurityToken;
             _tokenData = Globalfunction.GetTokenData(tokenS);
         }
     }
     catch (Exception ex)
     {
         Globalfunction.WriteSystemLog(ex.Message);
     }
 }
Esempio n. 4
0
        public dynamic ExecuteReader(string qry)
        {
            var retObject = new List <dynamic>();

            try
            {
                using (MySqlConnection conn = GetConnection())
                {
                    conn.Open();
                    MySqlCommand cmd = new MySqlCommand(qry, conn);
                    using (var dataReader = cmd.ExecuteReader())
                    {
                        while (dataReader.Read())
                        {
                            // var dataRow = new ExpandoObject() as IDictionary<string, object>;
                            var dataRow = new DynamicObject();
                            for (var iFiled = 0; iFiled < dataReader.FieldCount; iFiled++)
                            {
                                // one can modify the next line to
                                //   if (dataReader.IsDBNull(iFiled))
                                //       dataRow.Add(dataReader.GetName(iFiled), dataReader[iFiled]);
                                // if one want don't fill the property for NULL
                                dataRow.AddProperty(
                                    dataReader.GetName(iFiled),
                                    dataReader.IsDBNull(iFiled) ? null : dataReader[iFiled] // use null instead of {}
                                    );
                            }

                            retObject.Add(dataRow);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Globalfunction.WriteSystemLog(ex.Message);
            }
            return(retObject);
        }
        // [Authorize]
        public dynamic FileUpload(String functionname, string fileparam)
        {
            string filename = "";
            string ext      = "";

            byte[] data          = Convert.FromBase64String(fileparam);
            string decodedString = Encoding.UTF8.GetString(data);
            Char   delimiter     = '/';

            String[] substrings  = decodedString.Split(delimiter);
            dynamic  objresponse = null;

            // if (substrings.Length >= 2)
            // {
            //     path = substrings[0];
            //     ext = substrings[1];
            // }
            if (substrings.Length >= 1)
            {
                filename = substrings[0];
            }
            if (substrings.Length >= 2)
            {
                ext = substrings[1];
            }

            string returnStr   = "Fail to Upload";
            string retfilename = "";

            try
            {
                var    files             = Request.Form.Files;
                var    appsettingbuilder = new ConfigurationBuilder().AddJsonFile("appsettings.json");
                var    Configuration     = appsettingbuilder.Build();
                string baseDirecotry     = Configuration.GetSection("appSettings:downloadPath").Value;
                string folderPath        = "";
                //string customerName = "";
                //string CompanyName = "";
                folderPath = Configuration.GetSection("appSettings:uploadMemberProfile").Value;
                // folderPath = baseDirecotry + folderPath + "/";
                folderPath = baseDirecotry;
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                // folderPath=Path.Combine(webRootPath,folderPath);

                string existingFile = Directory.EnumerateFiles(folderPath, filename + ".*").FirstOrDefault();
                string extension    = "";
                if (!string.IsNullOrEmpty(existingFile))
                {
                    extension = Path.GetExtension(existingFile);
                }
                string oldPath = folderPath + filename + extension;
                // delete old photo
                if (System.IO.File.Exists(oldPath))     // Read data when file exists.
                {
                    System.IO.File.Delete(oldPath);
                }
                folderPath  = folderPath + filename + "." + ext;
                retfilename = filename + "." + ext;
                //Member newMemberobj = _repositoryWrapper.Member.FindByID(Convert.ToInt32(filename));

                // newMemberobj.loginname = newMemberobj.loginname;
                // newMemberobj.memberphone = newMemberobj.memberphone;
                // newMemberobj.memberdob = newMemberobj.memberdob;
                // newMemberobj.memberaddress = newMemberobj.memberaddress;
                // newMemberobj.password = newMemberobj.password;
                // newMemberobj.email = newMemberobj.email;

                // newMemberobj.membercardnumber = newMemberobj.membercardnumber;
                // newMemberobj.membername = newMemberobj.membername;;
                // newMemberobj.pointbalance = newMemberobj.pointbalance;
                // newMemberobj.totalpointbalance = newMemberobj.totalpointbalance;
                // newMemberobj.cardtypekwid = newMemberobj.cardtypekwid;
                // newMemberobj.embossstatus = newMemberobj.embossstatus;
                // newMemberobj.branchcode = newMemberobj.branchcode;
                // newMemberobj.expireddate = newMemberobj.expireddate;
                // newMemberobj.issuedate = newMemberobj.issuedate;
                // newMemberobj.memberdob = newMemberobj.memberdob;
                //newMemberobj.photo = decodedString;
                // newMemberobj.openingpoint = newMemberobj.openingpoint;
                // newMemberobj.isactive = newMemberobj.isactive;
                // newMemberobj.partnerid = newMemberobj.partnerid;
                // newMemberobj.createdate = newMemberobj.createdate;
                // newMemberobj.createuser = newMemberobj.createuser;; //! need to ask ?
                // newMemberobj.nrc = newMemberobj.nrc;
                // newMemberobj.nrctype = newMemberobj.nrctype;
                // newMemberobj.customer_type = newMemberobj.customer_type;
                // newMemberobj.openingpointamount = newMemberobj.openingpointamount;
                // newMemberobj.totalpointamount = newMemberobj.totalpointamount;
                // newMemberobj.version = newMemberobj.version;
                // newMemberobj.amount = newMemberobj.amount;
                // newMemberobj.liter = newMemberobj.liter;

                //_repositoryWrapper.Member.Update(newMemberobj);

                // Save the file
                var file = files[0];
                if (file.Length > 0)
                {
                    using (var fileStream = new FileStream(folderPath, FileMode.OpenOrCreate))
                    {
                        file.CopyTo(fileStream);
                    }
                }
                Response.ContentType = "application/json";
                returnStr            = "Succesfully Upload  " + retfilename;
                objresponse          = new { status = 1, messages = returnStr };
            }
            catch (Exception ex)
            {
                Globalfunction.WriteSystemLog(ex.Message);
                // _repositoryWrapper.EventLog.Error("fileUpload(Exception) : " , ex.Message, "", "");
                Response.StatusCode = 500;
                dynamic uu = null;
                objresponse = new { status = 0, messages = uu };
                return(objresponse);
                // return null;
            }

            return(objresponse);
        }