Exemple #1
0
        public IrisIdentity(User user)
        {
            if (user == null)
            {
                AsGuest();
                return;
            }

            UserName = user.UserName;
            //Email = user.Email;
            //FirstName = user.FirstName;
            //LastName = user.LastName;
            //Name = string.IsNullOrWhiteSpace(UserName) 
            //           ? user.Email
            //           : string.Format("{0} {1}", FirstName, LastName);

            Name = UserName;

            //try
            //{
            //    TimeZone = TimeZoneInfo.FindSystemTimeZoneById(user.TimeZone);
            //}
            //catch (Exception)
            //{
            //    TimeZone = TimeZoneInfo.Utc;
            //}

            Roles = new List<string> { user.Role.Name ?? "user" };
        }
Exemple #2
0
 public EditedUserStatus EditUser(User user)
 {
     User selectedUser = GetUserById(user.Id);
     if (selectedUser.UserName != user.UserName || selectedUser.Email != user.Email)
     {
         if (isUserNameAndEmailExist(user.UserName, user.Email))
         {
             return EditedUserStatus.UserNameOrEmailExist;
         }
     }
     selectedUser.Email = user.Email;
     selectedUser.IsBaned = user.IsBaned;
     selectedUser.Role = user.Role;
     if (user.BanedDate != null)
     {
         selectedUser.BanedDate = user.BanedDate;
     }
     if (!string.IsNullOrEmpty(user.Password))
     {
         selectedUser.Password = Encryption.EncryptingPassword(user.Password);
         selectedUser.LastPasswordChange = user.LastPasswordChange;
     }
     selectedUser.UserName = user.UserName;
     selectedUser.UserMetaData.BirthDay = user.UserMetaData.BirthDay;
     selectedUser.UserMetaData.Description = user.UserMetaData.Description;
     selectedUser.UserMetaData.FirstName = user.UserMetaData.FirstName;
     selectedUser.UserMetaData.LastName = user.UserMetaData.LastName;
     selectedUser.UserMetaData.Major = user.UserMetaData.Major;
     return EditedUserStatus.UpdatingUserSuccessfully;
 }
Exemple #3
0
        public AddUserStatus Add(User user)
        {
            if (ExistsByEmail(user.Email))
                return AddUserStatus.EmailExist;
            if (ExistsByUserName(user.UserName))
                return AddUserStatus.UserNameExist;

            _users.Add(user);
            return AddUserStatus.AddingUserSuccessfully;
        }
Exemple #4
0
 public int DisLike(int id, User user)
 {
     int likeCount = _pages.Find(id).LikeCount -= 1;
     _pages.Find(id).LikedUsers.Add(user);
     return likeCount;
 }
Exemple #5
0
        public virtual ActionResult Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return PartialView(MVC.User.Views._Register, model);
            }
            var newUser = new User
            {
                CreatedDate = DateAndTime.GetDateTime(),
                Email = model.Email,
                IP = Request.ServerVariables["REMOTE_ADDR"],
                IsBaned = false,
                UserName = model.UserName,
                Password = Encryption.EncryptingPassword(model.Password),
                UserMetaData = new UserMetaData(),
                Role = _roleService.GetRoleByRoleName("user"),
                LastLoginDate = DateAndTime.GetDateTime()
            };

            AddUserStatus addingNewUserResult = _userService.Add(newUser);

            if (addingNewUserResult == AddUserStatus.EmailExist)
            {
                ModelState.AddModelError("", "ایمیل وارد شده قبلا درسیستم ثبت شده است.");
                return PartialView(MVC.User.Views._Register, model);
            }

            if (addingNewUserResult == AddUserStatus.UserNameExist)
            {
                ModelState.AddModelError("", "نام کاربری تکراری است.");
                return PartialView(MVC.User.Views._Register, model);
            }

            _uow.SaveChanges();

            SetAuthCookie(model.UserName, "user", false);

            return Json(new { result = "success" });
        }
Exemple #6
0
        private static VerifyUserStatus Verify(User selectedUser, string password)
        {
            var result = VerifyUserStatus.VerifiedFaild;

            bool verifiedPassword = Encryption.VerifyPassword(password, selectedUser.Password);

            if (!verifiedPassword) return result;
            if (selectedUser.IsBaned)
            {
                result = VerifyUserStatus.UserIsbaned;
            }
            else
            {
                selectedUser.LastLoginDate = DateAndTime.GetDateTime();
                result = VerifyUserStatus.VerifiedSuccessfully;
            }

            return result;
        }
Exemple #7
0
 public int DisLike(int id, User user)
 {
     _posts.Find(id).Like -= 1;
     _posts.Find(id).LikedUsers.Add(user);
     return _posts.Find(id).Like;
 }
Exemple #8
0
 public int Like(int id, User user)
 {
     int likeCount = _articles.Find(id).LikeCount += 1;
     _articles.Find(id).LikedUsers.Add(user);
     return likeCount;
 }
Exemple #9
0
        public virtual ActionResult EditUser(EditUserModel userModel)
        {
            ModelState.Remove("BirthDay");
            if (!ModelState.IsValid)
                return PartialView(MVC.Admin.Shared.Views._ValidationSummery);

            var editedUser = new User
            {
                Email = userModel.Email,
                Id = userModel.Id,
                IsBaned = userModel.IsBaned,
                UserName = userModel.UserName,
                Role = _roleService.GetRoleByRoleId(userModel.RoleId),
                UserMetaData = new UserMetaData
                {
                    BirthDay = userModel.BirthDay,
                    Description = userModel.Description,
                    FirstName = userModel.FirstName,
                    LastName = userModel.LastName,
                    Major = userModel.Major
                }
            };

            if (!string.IsNullOrEmpty(userModel.Password))
            {
                editedUser.Password = userModel.Password;
                editedUser.LastPasswordChange = DateAndTime.GetDateTime();
            }
            if (userModel.IsBaned)
            {
                editedUser.BanedDate = DateAndTime.GetDateTime();
            }

            EditedUserStatus editingStatus = _userService.EditUser(editedUser);
            string message;
            switch (editingStatus)
            {
                case EditedUserStatus.UpdatingUserSuccessfully:
                    message = "اطلاعات کاربر با موفقیت به روز رسانی شد";
                    if (userModel.AvatarStatus == false)
                    {
                        AvatarImage.RemoveAvatarImage(userModel.UserName);
                    }
                    _uow.SaveChanges();
                    return PartialView(MVC.Admin.Shared.Views._Alert,
                        new Alert { Message = message, Mode = AlertMode.Success }); // user added successfully
                case EditedUserStatus.EmailExist:
                    message = "ایمیل وارد شده تکراری است";
                    break;
                case EditedUserStatus.UserNameExist:
                    message = "نام کاربری تکراری است";
                    break;
                default:
                    message = "نام کاربری یا ایمیل تکراری است";
                    break;
            }
            return PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Mode = AlertMode.Error, Message = message });
        }
Exemple #10
0
        public virtual ActionResult AddUser(AddUserModel userModel)
        {
            ModelState.Remove("BirthDay");
            if (!ModelState.IsValid)
                return PartialView(MVC.Admin.Shared.Views._ValidationSummery);

            var newUser = new User
            {
                Email = userModel.Email,
                IP = Request.ServerVariables["REMOTE_ADDR"],
                Password = Encryption.EncryptingPassword(userModel.Password),
                CreatedDate = DateAndTime.GetDateTime(),
                Role = _roleService.GetRoleByRoleId(userModel.RoleId),
                UserName = userModel.UserName,
                UserMetaData = new UserMetaData
                {
                    BirthDay = userModel.BirthDay,
                    Description = userModel.Description,
                    FirstName = userModel.FirstName,
                    LastName = userModel.LastName,
                    Major = userModel.Major,
                }
            };

            AddUserStatus status = _userService.Add(newUser);
            string message;
            if (status == AddUserStatus.AddingUserSuccessfully)
            {
                message = "کاربر جدید با موفقیت در سیستم ثبت شد";
                _uow.SaveChanges();
                return PartialView(MVC.Admin.Shared.Views._Alert,
                    new Alert { Message = message, Mode = AlertMode.Success });
            }
            switch (status)
            {
                case AddUserStatus.EmailExist:
                    message = "ایمیل وارد شده تکراری است";
                    break;
                case AddUserStatus.UserNameExist:
                    message = "نام کاربری تکراری است";
                    break;
                default:
                    message = "نام کاربری یا ایمیل تکراری است";
                    break;
            }
            return PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Mode = AlertMode.Error, Message = message });
        }
Exemple #11
0
 public int Like(int id, User user)
 {
     _comments.Find(id).LikedUsers.Add(user);
     return ++_comments.Find(id).LikeCount;
 }