示例#1
0
        public async Task <AuthResponse> ChangePassword(string email, string oldPassword, string newPassword)
        {
            var checkUser = await _schoolHubDbContext.User.FirstOrDefaultAsync(u => u.EmailAddress == email && u.Password == oldPassword && u.IsEmailConfirmed == false);

            CreatePasswordEncrypt(newPassword, out byte[] passwordHash, out byte[] passwordSalt);

            if (checkUser != null)
            {
                checkUser.Password         = newPassword;
                checkUser.PasswordHash     = passwordHash;
                checkUser.PasswordSalt     = passwordSalt;
                checkUser.IsEmailConfirmed = true;
            }
            _schoolHubDbContext.Entry(checkUser).State = EntityState.Modified;
            await _schoolHubDbContext.SaveChangesAsync();

            var response = new AuthResponse
            {
                Status  = true,
                Success = AuthResponseEnum.Yes.GetDescription()
            };

            //TODO: Send Email to User
            #region New Password Change Notification
            const int type = (int)NotificationType.PasswordChange;
            await _notificationProcessor.ProcessNotificationAsync(checkUser, type);

            #endregion
            return(response);
        }
示例#2
0
        public async Task <long> InsertUser(CreateUserDto model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            using (var txn = _schoolHubDbContext.Database.BeginTransaction())
            {
                CreatePasswordEncrypt(model.Password, out byte[] passwordHash, out byte[] passwordSalt);

                var newUser = new User
                {
                    Username         = model.Username,
                    Password         = model.Password,
                    EmailAddress     = model.EmailAddress,
                    PasswordHash     = passwordHash,
                    PasswordSalt     = passwordSalt,
                    IsEmailConfirmed = false,
                    IsUpdated        = false,
                    IsAdmin          = false,
                    UserType         = (int)model.UserType,
                };
                if (model.UserType == UserTypeEnum.Admin)
                {
                    newUser.IsAdmin = true;
                }
                await _schoolHubDbContext.User.AddAsync(newUser);

                await _schoolHubDbContext.SaveChangesAsync();

                //TODO: Send Email to User
                #region New Registration Notification
                const int type = (int)NotificationType.Registration;
                await _notificationProcess.ProcessNotificationAsync(newUser, type);

                #endregion
                txn.Commit();
                return(await Task.FromResult(newUser.Id));
            }
        }