예제 #1
0
        public ActionResult Login(VendorLoginModel _model)
        {
            var vendor = VendorHelper.Instance.GetVendorByEmail(_model.EmailId);

            if (vendor == null)
            {
                ModelState.AddModelError("EmailId", "Invalid Email Id");
            }
            else if (vendor.AdminApproval == 0)
            {
                TempData["Message"] = AppLogic.setFrontendMessage(1, "Your account is pending for approval. Please contact strataboard admin!");
            }
            else if (vendor.AdminApproval == 2)
            {
                TempData["Message"] = AppLogic.setFrontendMessage(1, "Your account has been rejected. Please contact strataboard admin!");
            }
            else if (vendor.Status != 1)
            {
                TempData["Message"] = AppLogic.setFrontendMessage(1, "Your account is deactive. Please contact strataboard admin!");
            }
            else
            {
                Encrypt64 enc   = new Encrypt64();
                var       pass  = enc.Encrypt(_model.Password);
                var       pass2 = enc.Decrypt(vendor.Password);
                if (vendor.Password == pass)
                {
                    Session["VendorId"]             = vendor.VendorId;
                    Session["VendorEmailId"]        = vendor.EmailId;
                    Session["VendorName"]           = vendor.VendorName;
                    Session["VendorMobile"]         = vendor.MobileNumber;
                    Session["VendorProfilePicture"] = vendor.ImageFile;
                    Session["VendorCreatedOn"]      = vendor.CreatedOn;

                    HttpCookie cookie = new HttpCookie("VendorCookie");

                    if (_model.RememberMe)
                    {
                        cookie.Values.Add("VendorEmail", enc.Encrypt(vendor.EmailId));
                        cookie.Values.Add("VendorPassword", vendor.Password);
                        cookie.Expires = DateTime.Now.AddDays(365);
                    }
                    else
                    {
                        cookie.Expires = DateTime.Now.AddDays(-1d);
                    }
                    Response.Cookies.Add(cookie);
                    return(RedirectToAction("Dashboard"));
                }
                else
                {
                    ModelState.AddModelError("Password", "Invalid Password");
                }
            }
            return(View(_model));
        }
예제 #2
0
        public int ChangeAdminPassword(ref ChangePasswordModel model)
        {
            Encrypt64 encrypt = new Encrypt64();

            model.NewPassword = encrypt.Encrypt(model.NewPassword, ConfigurationManager.AppSettings["SecureKey"].ToString());
            model.OldPassword = encrypt.Encrypt(model.OldPassword, ConfigurationManager.AppSettings["SecureKey"].ToString());
            SqlCommand    Cmd;
            string        msg = "";
            int           err = 0;
            SqlConnection Con = new SqlConnection(SqlHelper.GetConnectionString());

            Cmd             = new SqlCommand("Usp_ChangePassword", Con);
            Cmd.CommandType = CommandType.StoredProcedure;
            Cmd.Parameters.Add("@LoginId", SqlDbType.VarChar, 100);
            Cmd.Parameters.Add("@oldPassword", SqlDbType.VarChar, 100);
            Cmd.Parameters.Add("@newPassword", SqlDbType.VarChar, 100);
            Cmd.Parameters.Add("@Type", SqlDbType.Int);
            Cmd.Parameters.Add("@msg", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
            Cmd.Parameters.Add("@err", SqlDbType.Int).Direction         = ParameterDirection.Output;
            Cmd.Parameters["@LoginId"].Value     = AdminSessionData.AdminUserName;
            Cmd.Parameters["@oldPassword"].Value = model.OldPassword;
            Cmd.Parameters["@newPassword"].Value = model.NewPassword;
            Cmd.Parameters["@Type"].Value        = 1;
            try
            {
                Con.Open();
                Cmd.ExecuteNonQuery();
                msg           = (string)Cmd.Parameters["@msg"].Value;
                err           = (int)Cmd.Parameters["@err"].Value;
                model.Message = msg;
                return(err);
            }
            catch
            {
                throw;
            }
            finally
            {
                Con.Close();
                Cmd.Dispose();
            }
        }
예제 #3
0
        public int PerformActionOnUser(UserModel objUserModel)
        {
            int result = -1;

            try
            {
                Encrypt64    encrypt      = new Encrypt64();
                SqlParameter prmUserId    = SqlHelper.CreateParameter("@UserId", objUserModel.UserId);
                SqlParameter prmLoginId   = SqlHelper.CreateParameter("@LoginId", objUserModel.LoginId);
                SqlParameter prmPassword  = SqlHelper.CreateParameter("@Password", encrypt.Encrypt(objUserModel.Password, ConfigurationManager.AppSettings["SecureKey"].ToString()));
                SqlParameter prmFirstName = SqlHelper.CreateParameter("@FirstName", objUserModel.FirstName);
                SqlParameter prmLastName  = SqlHelper.CreateParameter("@LastName", objUserModel.LastName);
                SqlParameter prmEmailId   = SqlHelper.CreateParameter("@EmailId", objUserModel.EmailId);
                SqlParameter prmRoleId    = SqlHelper.CreateParameter("@RoleId", objUserModel.RoleId);
                if (objUserModel.RoleId == 1)
                {
                    objUserModel.Status = 1;
                }
                SqlParameter prmGender        = SqlHelper.CreateParameter("@Gender", objUserModel.Gender);
                SqlParameter prmDOB           = SqlHelper.CreateParameter("@DateOfBirth", objUserModel.DOB == null ? Convert.ToDateTime("1/1/1900") : Convert.ToDateTime(objUserModel.DOB));
                SqlParameter prmStatus        = SqlHelper.CreateParameter("@Status", objUserModel.Status);
                SqlParameter prmCreatedBy     = SqlHelper.CreateParameter("@CreatedBy", objUserModel.CreatedBy);
                SqlParameter prmCreatedFromIp = SqlHelper.CreateParameter("@CreatedFromIp", objUserModel.CreatedFromIp);
                SqlParameter prmUserType      = SqlHelper.CreateParameter("@UserType", objUserModel.UserType);

                SqlParameter prmFlag = SqlHelper.CreateParameter("@Flag", objUserModel.Flag);
                SqlParameter prmErr  = SqlHelper.CreateParameter("@Err", -1, ParameterDirection.Output);

                SqlParameter[] allParams = { prmUserId, prmLoginId, prmPassword, prmFirstName, prmLastName, prmEmailId, prmRoleId, prmGender, prmDOB, prmStatus, prmCreatedBy, prmCreatedFromIp, prmUserType, prmFlag, prmErr };
                SqlHelper.ExecuteNonQuery(_conString, CommandType.StoredProcedure, "Usp_AddUpAdminUser", allParams);

                if (prmErr.Value != null)
                {
                    result = (int)prmErr.Value;
                }
            }
            catch
            {
                throw;
            }

            return(result);
        }
예제 #4
0
 public ActionResult ResetPassword(ResetPasswordModel model)
 {
     try
     {
         if (VendorHelper.Instance.ResetVendorPassword(model.EmailId, enc.Encrypt(model.NewPassword)) > 0)
         {
             TempData["Message"] = AppLogic.setFrontendMessage(0, "Password reset successfully");
             return(RedirectToAction("login"));
         }
         else
         {
             TempData["Message"] = AppLogic.setFrontendMessage(1, "Password reset failed");
             return(View(new ResetPasswordModel()
             {
                 EmailId = model.EmailId
             }));
         }
     }
     catch
     {
         TempData["Message"] = AppLogic.setFrontendMessage(1, "Error: Password reset failed");
         return(RedirectToAction("login"));
     }
 }
예제 #5
0
        public DataTable AuthenticateUser(LogOnModel objModel, out int result)
        {
            try
            {
                Encrypt64 encrypt = new Encrypt64();
                objModel.Password = encrypt.Encrypt(objModel.Password, ConfigurationManager.AppSettings["SecureKey"].ToString());

                result     = -1;
                _conString = SqlHelper.GetConnectionString();
                SqlParameter   prmUserName = SqlHelper.CreateParameter("@LoginId", objModel.UserName);
                SqlParameter   prmPassword = SqlHelper.CreateParameter("@Password", objModel.Password);
                SqlParameter   prmUserType = SqlHelper.CreateParameter("@UserType", objModel.UserType);
                SqlParameter   prmErr      = SqlHelper.CreateParameter("@Err", -1, ParameterDirection.Output);
                SqlParameter[] allParams   = { prmUserName, prmPassword, prmUserType, prmErr };
                DataSet        ds          = SqlHelper.ExecuteDataset(_conString, CommandType.StoredProcedure, "Usp_AuthenticateUser", allParams);
                if (prmErr.Value != null)
                {
                    result = (int)prmErr.Value;
                }

                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable Dt = ds.Tables[0].Copy();
                    ds.Dispose();
                    return(Dt);
                }
                else
                {
                    return((DataTable)null);
                }
            }
            catch
            {
                throw;
            }
        }
예제 #6
0
        public long AddNewVendor(VendorModel objectModel, HttpPostedFileBase image, HttpPostedFileBase tradeFile)
        {
            long _vendorId = -2;

            if (!IsEmailExists(objectModel.EmailId))
            {
                if (image != null)
                {
                    Guid g = Guid.NewGuid();
                    objectModel.ActualImageFile = image.FileName;
                    objectModel.ImageFile       = g.ToString() + Path.GetExtension(image.FileName);
                }

                if (tradeFile != null)
                {
                    Guid g2 = Guid.NewGuid();
                    objectModel.ActualTradeAndBusinessFile = tradeFile.FileName;
                    objectModel.TradeAndBusinessFile       = g2.ToString() + Path.GetExtension(tradeFile.FileName);
                }
                tblVendor tblVendorDb = new tblVendor();
                tblVendorDb.VendorName                 = objectModel.VendorName;
                tblVendorDb.EmailId                    = objectModel.EmailId;
                tblVendorDb.DisciplineId               = objectModel.DisciplineId;
                tblVendorDb.OtherDisciplineName        = objectModel.OtherDisciplineName;
                tblVendorDb.MobileNumber               = objectModel.MobileNumber;
                tblVendorDb.CompanyBrief               = objectModel.CompanyBrief;
                tblVendorDb.TradeAndBusinessFile       = objectModel.TradeAndBusinessFile;
                tblVendorDb.ActualTradeAndBusinessFile = objectModel.ActualTradeAndBusinessFile;
                tblVendorDb.ImageFile                  = objectModel.ImageFile;
                tblVendorDb.ActualImageFile            = objectModel.ActualImageFile;
                tblVendorDb.AdminApproval              = 0;
                tblVendorDb.Status = 1;
                Encrypt64 enc = new Encrypt64();
                tblVendorDb.Password      = enc.Encrypt(AppLogic.GenerateRandomString(8));
                tblVendorDb.CreatedOn     = DateTime.UtcNow;
                tblVendorDb.CreatedFromIp = HttpContext.Current.Request.UserHostAddress;
                using (StratasFairDBEntities context = new StratasFairDBEntities())
                {
                    context.tblVendors.Add(tblVendorDb);
                    context.SaveChanges();
                }
                _vendorId = tblVendorDb.VendorId;
                try
                {
                    if (_vendorId > 0)
                    {
                        string path        = string.Empty;
                        int    fileMapped  = -1;
                        string initialPath = "resources/vendor/" + _vendorId;

                        if (image != null)
                        {
                            // Add/Delete the new trade and business file and image details
                            if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/ProfilePicture/")))
                            {
                                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/ProfilePicture/"));
                            }
                            // save the file locally
                            path = HttpContext.Current.Server.MapPath(Path.Combine("~/Content/" + initialPath + "/ProfilePicture/" + objectModel.ImageFile));
                            image.SaveAs(path);

                            // save the file on s3
                            fileMapped = AwsS3Bucket.CreateFile(initialPath + "/ProfilePicture/" + objectModel.ImageFile, path);

                            // delete the file locally
                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }
                        }
                        if (tradeFile != null)
                        {
                            // Add/Delete the new trade and business file and image details
                            if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/TradeFile/")))
                            {
                                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Content/" + initialPath + "/TradeFile/"));
                            }
                            // save the file locally
                            path = HttpContext.Current.Server.MapPath(Path.Combine("~/Content/" + initialPath + "/TradeFile/" + objectModel.TradeAndBusinessFile));
                            tradeFile.SaveAs(path);

                            // save the file on s3
                            fileMapped = AwsS3Bucket.CreateFile(initialPath + "/TradeFile/" + objectModel.TradeAndBusinessFile, path);

                            //delete the file locally
                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    new AppError().LogMe(ex);
                    // any error is there
                }
                return(_vendorId);
            }
            else
            {
                return(-3);
            }
        }