예제 #1
0
        /// <summary>
        /// Post action for getting the password and confirm password and resetting it.
        /// If the user id and reset code doesn't match with database, the error message showed here, otherwise it will show the change password form.
        /// After changed the password, the user will be redirected to the login page.
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdatePassword()
        {
            FormsAuthentication.SignOut();
            Session.Abandon();
            var userId     = Convert.ToInt32(Request["userId"]);
            var code       = Request["recoveryCode"];
            var password   = Request["password"];
            var userDetail = _userManagement.FindUserByUserId(userId);

            if (userDetail.ResetPasswordCode == code)
            {
                var encrypt           = new Cryptography();
                var encryptedPassword = Convert.ToBase64String(encrypt.Encryption(password));
                var updateColumns     = new List <UpdateColumn>
                {
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.Password,
                        Value      = encryptedPassword
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ModifiedDate,
                        Value      = DateTime.UtcNow.ToString(GlobalAppSettings.GetDateTimeFormat())
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ResetPasswordCode,
                        Value      = _userManagement.GenerateRandomCode(12)
                    },
                };
                var result = _userManagement.UpdateUserProfileDetails(updateColumns, userId);
                if (result)
                {
                    TempData["User"] = "******";
                    return(Redirect("../login"));
                }
                else
                {
                    TempData["Message"] = "Internal server error while updating password. Please try again.";
                    return(Redirect("../forgot-Password/change-password?userid=" + userId + "&recovercode=" + code));
                }
            }
            TempData["Message"] = "Invalid link";
            return(Redirect("../accounts/forgot-Password/change-password?userid=" + userId + "&recovercode=" + code));
        }
예제 #2
0
        public bool DeleteAvatar(int userId)
        {
            var updateColumns = new List <UpdateColumn>
            {
                new UpdateColumn
                {
                    ColumnName = GlobalAppSettings.DbColumns.DB_User.Picture,
                    Value      = null
                },
                new UpdateColumn
                {
                    ColumnName = GlobalAppSettings.DbColumns.DB_User.ModifiedDate,
                    Value      = DateTime.UtcNow.ToString(GlobalAppSettings.GetDateTimeFormat())
                }
            };

            return(_userDetails.UpdateUserProfileDetails(updateColumns, userId));
        }
예제 #3
0
        public JsonResult ActivateUser()
        {
            var        userId = userDetails.GetUserId(Request["username"]);
            var        output = new Dictionary <string, string>();
            JsonResult jsonOutput;

            try
            {
                var userobj = new User
                {
                    FirstName                = Request["firstname"],
                    UserName                 = Request["username"],
                    Email                    = Request["email"],
                    ActivationCode           = userDetails.GenerateRandomCode(12),
                    ActivationExpirationDate =
                        DateTime.UtcNow.AddDays(GlobalAppSettings.SystemSettings.ActivationExpirationDays)
                };
                const bool isResendActivationCode = false;
                var        activationUrl          = GlobalAppSettings.SystemSettings.BaseUrl + "/accounts/activate?ActivationCode=" +
                                                    userobj.ActivationCode;

                var updateColumns = new List <UpdateColumn>
                {
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ModifiedDate,
                        Value      = DateTime.UtcNow.ToString(GlobalAppSettings.GetDateTimeFormat())
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ActivationCode,
                        Value      = userobj.ActivationCode
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ActivationExpirationDate,
                        Value      = userobj.ActivationExpirationDate.ToString(GlobalAppSettings.GetDateTimeFormat())
                    }
                };

                var result = userDetails.UpdateUserProfileDetails(updateColumns, userId);
                if (result)
                {
                    UserManagementModel.SendActivationCode(userobj.FirstName, userobj.UserName, userobj.Email,
                                                           activationUrl, userobj.ActivationExpirationDate, isResendActivationCode);
                    output.Add("result", "success");
                    jsonOutput = Json(new { Data = output });
                }
                else
                {
                    output.Add("result", "error");
                    jsonOutput = Json(new { Data = output });
                }
            }
            catch (Exception)
            {
                output.Add("result", "error");
                jsonOutput = Json(new { Data = output });
            }

            return(jsonOutput);
        }
예제 #4
0
        public JsonResult UpdateUserProfile()
        {
            int userId             = this.userDetails.GetUserId(HttpContext.Request["username"]);
            var currentUserDetails = this.userDetails.FindUserByUserId(userId);
            var currentEmail       = currentUserDetails.Email;
            var timeNow            = DateTime.UtcNow;

            if (currentEmail != HttpContext.Request["email"])
            {
                var emailList = this.userDetails.GetAllActiveEmails();

                var isEmailExist = emailList.Find(f => f.Email == HttpContext.Request["email"]) == null;

                if (isEmailExist)
                {
                    var updateColumns = new List <UpdateColumn>
                    {
                        new UpdateColumn
                        {
                            ColumnName = GlobalAppSettings.DbColumns.DB_User.Email,
                            Value      = HttpContext.Request["email"]
                        }
                    };
                    this.userDetails.UpdateUserProfileDetails(updateColumns, userId);
                }
                else
                {
                    var result = new { status = false, key = "email", value = "E-mail already exists" };
                    return(Json(new { Data = result }));
                }
            }
            try
            {
                var fullName = currentUserDetails.FirstName;

                if (fullName != HttpContext.Request["firstname"])
                {
                    var updateColumns = new List <UpdateColumn>
                    {
                        new UpdateColumn
                        {
                            ColumnName = GlobalAppSettings.DbColumns.DB_User.FirstName,
                            Value      = HttpContext.Request["fullname"]
                        }
                    };
                    this.userDetails.UpdateUserProfileDetails(updateColumns, userId);
                }
                var updateDetails = new List <UpdateColumn>
                {
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.FirstName,
                        Value      = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(HttpContext.Request["firstname"])
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.LastName,
                        Value      = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(HttpContext.Request["lastname"])
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.Contact,
                        Value      = HttpContext.Request["mobile"]
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.DisplayName,
                        Value      =
                            CultureInfo.CurrentCulture.TextInfo.ToTitleCase(HttpContext.Request["firstname"]) + " " +
                            CultureInfo.CurrentCulture.TextInfo.ToTitleCase(HttpContext.Request["lastname"])
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ModifiedDate,
                        Value      = timeNow.ToString(GlobalAppSettings.GetDateTimeFormat())
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.IsActive,
                        Value      = HttpContext.Request["status"]
                    }
                };
                this.userDetails.UpdateUserProfileDetails(updateDetails, userId);
            }
            catch (Exception)
            {
                var result = new { status = false, key = "error", value = "User profile updation has been failed" };
                return(Json(new { Data = result }));
            }
            var formattedString = GetFormattedTimeZone(timeNow, userId);
            var finalResult     = new { status = true, key = "success", value = "User profile has been updated successfully." };

            return(Json(new { Data = finalResult, formattedString }));
        }
예제 #5
0
        public string UpdateUserAvatarDetails(ProfilePicture profile, DateTime timeNow)
        {
            var userManagement = new UserManagement();

            try
            {
                var destination = GlobalAppSettings.GetProfilePicturesPath();
                var newlocation = destination + profile.UserName;
                var imageName   = Guid.NewGuid().ToString();

                var imageLocation150 = newlocation + "\\150\\";
                var imageLocation110 = newlocation + "\\110\\";
                var imageLocation64  = newlocation + "\\64\\";
                var imageLocation32  = newlocation + "\\32\\";
                var imageLocation18  = newlocation + "\\18\\";

                if (!Directory.Exists(imageLocation150))
                {
                    Directory.CreateDirectory(imageLocation150);
                }
                if (!Directory.Exists(imageLocation110))
                {
                    Directory.CreateDirectory(imageLocation110);
                }
                if (!Directory.Exists(imageLocation64))
                {
                    Directory.CreateDirectory(imageLocation64);
                }
                if (!Directory.Exists(imageLocation32))
                {
                    Directory.CreateDirectory(imageLocation32);
                }
                if (!Directory.Exists(imageLocation18))
                {
                    Directory.CreateDirectory(imageLocation18);
                }

                imageLocation150 = imageLocation150 + imageName + ".png";
                imageLocation110 = imageLocation110 + imageName + ".png";
                imageLocation64  = imageLocation64 + imageName + ".png";
                imageLocation32  = imageLocation32 + imageName + ".png";
                imageLocation18  = imageLocation18 + imageName + ".png";

                newlocation = newlocation + "\\" + profile.ImageName;

                var resizedImage = Image.FromFile(newlocation);

                var bitMapImage = new Bitmap(200, 200);

                using (var graphicImageContent = Graphics.FromImage(bitMapImage))
                {
                    graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
                    graphicImageContent.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphicImageContent.SmoothingMode      = SmoothingMode.HighQuality;
                    graphicImageContent.DrawImage(resizedImage, 0, 0, bitMapImage.Width, bitMapImage.Height);
                }

                var croppedImage =
                    bitMapImage.Clone(
                        new Rectangle(profile.LeftOfCropArea, profile.TopOfCropAea,
                                      profile.Height, profile.Width),
                        resizedImage.PixelFormat);
                var newBitmap = new Bitmap(croppedImage);

                using (var graphicImageContent = Graphics.FromImage(bitMapImage))
                {
                    graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
                    graphicImageContent.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphicImageContent.SmoothingMode      = SmoothingMode.HighQuality;
                    graphicImageContent.DrawImage(newBitmap, 0, 0, bitMapImage.Width, bitMapImage.Height);
                }
                var cropBitmap150 = new Bitmap(bitMapImage);
                cropBitmap150.Save(imageLocation150, ImageFormat.Png);

                bitMapImage = new Bitmap(110, 110);
                using (var graphicImageContent = Graphics.FromImage(bitMapImage))
                {
                    graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
                    graphicImageContent.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphicImageContent.SmoothingMode      = SmoothingMode.HighQuality;
                    graphicImageContent.DrawImage(newBitmap, 0, 0, bitMapImage.Width, bitMapImage.Height);
                }
                var cropBitmap110 = new Bitmap(bitMapImage);
                cropBitmap110.Save(imageLocation110, ImageFormat.Png);

                bitMapImage = new Bitmap(64, 64);
                using (var graphicImageContent = Graphics.FromImage(bitMapImage))
                {
                    graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
                    graphicImageContent.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphicImageContent.SmoothingMode      = SmoothingMode.HighQuality;
                    graphicImageContent.DrawImage(newBitmap, 0, 0, bitMapImage.Width, bitMapImage.Height);
                }
                var cropBitmap64 = new Bitmap(bitMapImage);
                cropBitmap64.Save(imageLocation64, ImageFormat.Png);

                bitMapImage = new Bitmap(32, 32);
                using (var graphicImageContent = Graphics.FromImage(bitMapImage))
                {
                    graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
                    graphicImageContent.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphicImageContent.SmoothingMode      = SmoothingMode.HighQuality;
                    graphicImageContent.DrawImage(newBitmap, 0, 0, bitMapImage.Width, bitMapImage.Height);
                }
                var cropBitmap32 = new Bitmap(bitMapImage);
                cropBitmap32.Save(imageLocation32, ImageFormat.Png);

                bitMapImage = new Bitmap(18, 18);
                using (var graphicImageContent = Graphics.FromImage(bitMapImage))
                {
                    graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
                    graphicImageContent.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphicImageContent.SmoothingMode      = SmoothingMode.HighQuality;
                    graphicImageContent.DrawImage(newBitmap, 0, 0, bitMapImage.Width, bitMapImage.Height);
                }
                var cropBitmap18 = new Bitmap(bitMapImage);
                cropBitmap18.Save(imageLocation18, ImageFormat.Png);

                var resultedImageName = imageName + ".png";

                var updateColumns = new List <UpdateColumn>
                {
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.Picture,
                        Value      = resultedImageName
                    },
                    new UpdateColumn
                    {
                        ColumnName = GlobalAppSettings.DbColumns.DB_User.ModifiedDate,
                        Value      = timeNow.ToString(GlobalAppSettings.GetDateTimeFormat())
                    }
                };

                userManagement.UpdateUserProfileDetails(updateColumns, profile.UserId);

                return(resultedImageName);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }