public HttpResponseMessage Put(int id, [FromBody] TeacherViewModel teacherViewModel)
        {
            try
            {
                var userId    = this.User.FindFirstValue(ClaimTypes.Name);
                var tempUsers = AutoMapper.Mapper.Map <Users>(teacherViewModel);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = Convert.ToInt32(userId);
                tempUsers.Password    = EncryptLib.EncryptText(teacherViewModel.Password);
                _users.UpdateUsers(tempUsers);
                var tempTeacher = AutoMapper.Mapper.Map <Teacher>(teacherViewModel);
                _teacher.UpdateTeacher(tempTeacher);
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            catch (Exception)
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
                return(response);
            }
        }
示例#2
0
        public HttpResponseMessage Post([FromBody] CoordinatorViewModel coordinator)
        {
            if (ModelState.IsValid)
            {
                var userId    = this.User.FindFirstValue(ClaimTypes.Name);
                var tempUsers = AutoMapper.Mapper.Map <Users>(coordinator);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = Convert.ToInt32(userId);
                tempUsers.Password    = EncryptLib.EncryptText(coordinator.Password);
                _users.InsertUsers(tempUsers);
                var tempCoordinator = AutoMapper.Mapper.Map <Coordinator>(coordinator);
                tempCoordinator.UserId = tempUsers.UserId;
                _coordinator.InsertCoordinator(tempCoordinator);
                UsersInRoles usersInRoles = new UsersInRoles();
                usersInRoles.RoleId = 4;
                usersInRoles.UserId = tempCoordinator.UserId;
                _usersInRoles.AssignRole(usersInRoles);

                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            else
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }
示例#3
0
        public HttpResponseMessage Put(int id, [FromBody] StudentViewModel studentViewModel)
        {
            try
            {
                int userId    = Convert.ToInt32(this.User.FindFirstValue(ClaimTypes.Name));
                int coorid    = _coordinator.GetCoordinatorId(userId);
                var tempUsers = AutoMapper.Mapper.Map <Users>(studentViewModel);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = Convert.ToInt32(coorid);
                tempUsers.Password    = EncryptLib.EncryptText(studentViewModel.Password);
                _users.UpdateUsers(tempUsers);
                var tempStudent = AutoMapper.Mapper.Map <Student>(studentViewModel);
                _student.UpdateStudent(tempStudent);
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            catch (Exception)
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
                return(response);
            }
        }
        public void Encrypt()
        {
            EncryptLib lib       = new EncryptLib();
            string     original  = "Hello World!";
            string     encrypted = lib.Encrypt(original);

            Assert.AreNotEqual(original, encrypted);
        }
        public void PrivateCertificate()
        {
            EncryptLib lib  = new EncryptLib();
            var        cert = lib.GetCertificate(true);

            Assert.IsNotNull(cert);
            Assert.IsTrue(cert.HasPrivateKey);
        }
        public void PublicCertificate()
        {
            EncryptLib lib  = new EncryptLib();
            var        cert = lib.GetCertificate(false);

            Assert.IsNotNull(cert);
            Assert.IsFalse(cert.HasPrivateKey);
        }
        /// <summary>
        /// validating login credentials
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="passWord"></param>
        /// <param name="auth_type"></param>
        /// <returns></returns>
        public string Login(string userName, string passWord, string auth_type)
        {
            //Session["MyMenu"] = null;

            log.Info("Login method");
            try
            {
                errorCode = 0;
                errorDesc = string.Empty;

                if (string.IsNullOrEmpty(userName))
                {
                    return("Please enter the Username");
                }
                else if (string.IsNullOrEmpty(passWord))
                {
                    return("Please enter the Password");
                }
                else
                {
                    List <UserMaster> lst = _dbOperations.GetUser(userName);

                    if (lst.Count > 0)
                    {
                        if (lst[0].IsADUser == "No" && passWord == EncryptLib.DecodeFrom64(lst[0].Password))
                        {
                            FormsAuthentication.SetAuthCookie(userName, false);
                            Session["UserName"] = userName;
                            return("Logged in successfully");
                        }
                        else if ((userName == lst[0].userId) && passWord == "welcome@17")
                        {
                            FormsAuthentication.SetAuthCookie(userName, false);
                            Session["UserName"] = userName;
                            return("Logged in successfully");
                        }
                        else
                        {
                            log.Info("Login failed for the user " + userName);
                            return("Login failed please check the credentials");
                        }
                    }

                    else
                    {
                        log.Info("Login failed for the user " + userName + " error code " + errorCode);
                        return("Login failed please check the credentials you entered");
                    }
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Exception Occured :{0}", ex.ToString());
                log.ErrorFormat("Exception Trace Message :{0}", ex.StackTrace);
                return("Invalid login detail");
            }
        }
        public IActionResult Post([FromBody] LoginRequestViewModel value)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var loginstatus = _users.AuthenticateUsers(value.UserName, EncryptLib.EncryptText(value.Password));

                    if (loginstatus)
                    {
                        var userdetails = _users.GetUserDetailsbyCredentials(value.UserName);

                        if (userdetails != null)
                        {
                            var tokenHandler    = new JwtSecurityTokenHandler();
                            var key             = Encoding.ASCII.GetBytes(_appSettings.Secret);
                            var tokenDescriptor = new SecurityTokenDescriptor
                            {
                                Subject = new ClaimsIdentity(new Claim[]
                                {
                                    new Claim(ClaimTypes.Name, userdetails.UserId.ToString())
                                }),
                                Expires            = DateTime.UtcNow.AddDays(1),
                                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key),
                                                                            SecurityAlgorithms.HmacSha256Signature)
                            };
                            var token = tokenHandler.CreateToken(tokenDescriptor);
                            value.Token = tokenHandler.WriteToken(token);

                            // remove password before returning
                            value.Password = null;
                            value.Usertype = userdetails.RoleId;

                            return(Ok(value));
                        }
                        else
                        {
                            value.Password = null;
                            value.Usertype = 0;
                            return(Ok(value));
                        }
                    }
                    value.Password = null;
                    value.Usertype = 0;
                    return(Ok(value));
                }
                value.Password = null;
                value.Usertype = 0;
                return(Ok(value));
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#9
0
        public int ChangePassword(string LoginId, string password)
        {
            AuthUserModel data = new AuthUserModel
            {
                loginId  = LoginId,
                password = EncryptLib.Encrypt(password)
            };

            var response = GetDataFromApiOut <BaseResultAPI <int>, AuthUserModel>(
                "Login/ChangePassword",
                Method.POST,
                null,
                null,
                data);

            return(response.Data);
        }
示例#10
0
        public HttpResponseMessage Post([FromBody] UsersViewModel users)
        {
            if (ModelState.IsValid)
            {
                if (_users.CheckUsersExits(users.UserName))
                {
                    var response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.Conflict
                    };

                    return(response);
                }
                else
                {
                    var userId    = this.User.FindFirstValue(ClaimTypes.Name);
                    var tempUsers = AutoMapper.Mapper.Map <Users>(users);
                    tempUsers.CreatedDate = DateTime.Now;
                    tempUsers.Createdby   = Convert.ToInt32(userId);
                    tempUsers.Password    = EncryptLib.EncryptText(users.Password);
                    _users.InsertUsers(tempUsers);

                    var response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK
                    };

                    return(response);
                }
            }
            else
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }
        public HttpResponseMessage Post([FromBody] TeacherViewModel teacher)
        {
            if (ModelState.IsValid)
            {
                int userId    = Convert.ToInt32(this.User.FindFirstValue(ClaimTypes.Name));
                int coorid    = _coordinator.GetCoordinatorId(userId);
                var tempUsers = AutoMapper.Mapper.Map <Users>(teacher);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = userId;
                tempUsers.Password    = EncryptLib.EncryptText(teacher.Password);
                _users.InsertUsers(tempUsers);
                var tempTeacher = AutoMapper.Mapper.Map <Teacher>(teacher);
                tempTeacher.DepartmentId = _coordinator.GetCoordinatorDepartmentId(coorid);
                tempTeacher.CreatedBy    = coorid;
                tempTeacher.UserID       = tempUsers.UserId;
                _teacher.InsertTeacher(tempTeacher);
                UsersInRoles usersInRoles = new UsersInRoles();
                usersInRoles.RoleId = 3;
                usersInRoles.UserId = tempTeacher.UserID;
                _usersInRoles.AssignRole(usersInRoles);

                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            else
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }