예제 #1
0
        public DomainModelResponse Add(UserAddRequest request)
        {
            EntityModel.Role role = _repRole.Get(filter: f => f.RoleCode == request.RoleCode).FirstOrDefault();

            UserProfile up = new UserProfile()
            {
                EmailId = request.emailId,
                FirstName = request.firstName,
                LastName = request.lastName,
                HashedPassword = createHash(request.password),
                SecurityQuestion = request.securityQuestion,
                HashedAnswer = createHash(request.answer),
                isAdmin = request.isAdmin,
                LastChangedTime = DateTime.UtcNow,
                LastPasswordChangeDate = DateTime.UtcNow,
                PasswordExpired = false,
                CourseUserRoles = null
            };
            _repUser.Add(up);
            _uow.Commit();
            AddUserToCourse(new UpdateUserCourse() { courseCode = "Default", emailId = request.emailId, RoleCode = request.RoleCode });
            _securityResponse.addResponse("Add", MessageCodes.InfoCreatedSuccessfully, "User");
            return _securityResponse;
        }
        private Token InternalCreateToken(UserProfile up, bool isPasswordExpire = false)
        {
            DateTime dtNow = DateTime.UtcNow;
            string sToken = String.Format("{0}:{1}", Guid.NewGuid().ToString(), dtNow.AddHours(3.0).ToString("yyyyMMddHHmmss"));
            sToken = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(sToken));
            Token t = new Token()
            {
                token = String.Concat(_tokenPrefix, sToken),
                maxSessionTime = isPasswordExpire ? 30 : 120,
                remainingTime = isPasswordExpire ? 30 : 120,
                passwordExpired = isPasswordExpire,
                message = isPasswordExpire ? "Password expired. Use this token to reset password." : null,
                user = new UserGetResponse()
                {
                    emailId = up.EmailId,
                    firstName = up.FirstName,
                    lastName = up.LastName,
                    isAdmin = (up.isAdmin == null) ? false : (bool) up.isAdmin,
                    UserCourseDetails = mapCourseDetails(up.CourseUserRoles)
                }
            };

            _repSessionToken.Add(new SessionToken
            {
                Token = t.token,
                CreationTimeUtc = DateTime.UtcNow,
                HasPasswordExpired = isPasswordExpire,
                LastActivityTimeUtc = DateTime.UtcNow,
                UserId = up.UserId,
                User = up,
                UserName = up.EmailId
            });
            _uow.Commit();
            return t;
        }