Exemple #1
0
        public LoginDetail SignIn(SignInDetail signin)
        {
            logger.Info("Inside Userservice/SignIn");
            LoginDetail loginResult       = new LoginDetail();
            string      pwd               = String.Empty;
            DateTime    passwordResetDate = new DateTime();
            string      salt              = String.Empty;

            try
            {
                var userDetail = unitOfWork.DbContext.UserDetail
                                 .Where(ud => string.Compare(ud.Email, signin.Email, true) == 0)
                                 .FirstOrDefault();

                if (userDetail == null)
                {
                    loginResult.Result = 7;
                    logger.Info("Invalid UserName");
                }
                else
                {
                    bool validPassword = PasswordManager.IsPasswordMatch(signin.Password, userDetail.Salt, userDetail.Password);
                    if (!validPassword)
                    {
                        loginResult.Result = 8;
                        logger.Info("Invalid password");
                    }
                    else
                    {
                        passwordResetDate = unitOfWork.DbContext.PasswordResetMapping
                                            .Where(prm => prm.UserId == userDetail.ID)
                                            .OrderByDescending(prm => prm.PasswordResetOn)
                                            .Select(prm => prm.PasswordResetOn).
                                            FirstOrDefault();

                        loginResult.Permission = userDetail.PermissionLevelMapping.OrderByDescending(plm => plm.CreationDate).Select(plm => plm.PermissionLevel.Permission).FirstOrDefault();


                        loginResult.PasswordResetOn = passwordResetDate;
                        loginResult.UserId          = userDetail.ID;
                        loginResult.UserName        = userDetail.Name;
                        loginResult.setByAdmin      = userDetail.SetByAdmin;
                        loginResult.StatusMessage   = "Valid User.Login Successful";
                        logger.Info("Valid User.Login Successful.");
                    }
                }
                return(loginResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public IHttpActionResult SignIn(SignInDetail signin)
        {
            logger.Info("Inside Login/SignIn");
            ActionStatus status      = new ActionStatus();
            LoginDetail  loginDetail = new LoginDetail();

            try
            {
                loginDetail = userService.SignIn(signin);
                if (loginDetail.Result == 2)
                {
                    logger.Info("Login Unsuccessful.Invalid Password");
                    throw new PasswordNotValidException();
                }
                else if (loginDetail.Result == 3)
                {
                    logger.Info("Login Unsuccessful.Invalid User");
                    throw new UserNotValidException();
                }
            }
            catch (UserServiceException ex)
            {
                status.Number = (int)ex.ErrorCodeService;
                if (status.Number == 7)
                {
                    status.Message = "Login unsuccessful.Invalid User.";
                }
                else if (status.Number == 8)
                {
                    status.Message = "Login Unsuccessful.Invalid Password";
                }
            }

            catch (Exception ex)
            {
                status.Number = -1;
                logger.Error("Exception in Login/SignIn: {0} \r\n {1}", ex.ToString(), ex.StackTrace);
            }

            if (status.Number != -1)
            {
                return(Ok(new { LoginDetail = loginDetail, Status = status }));
            }
            else
            {
                return(InternalServerError());
            }
        }
Exemple #3
0
        private LoginDetail AuthenticateUser(OAuthGrantResourceOwnerCredentialsContext context, string passwordResetOn)
        {
            //string conStr = ConfigurationManager.ConnectionStrings["DefaultConnection"]?.ToString();
            // var sql = "select * from userDetail where email = @userName and password = @pwd";
            try
            {
                //using (SqlConnection conn = new SqlConnection(conStr))
                //{
                //using (SqlCommand cmd = new SqlCommand(sql, conn))
                //{
                //    cmd.CommandType = CommandType.Text;
                //    cmd.Parameters.AddWithValue("userName", context.UserName);
                //    //var md5Hash = BitConverter.ToString(MD5.Create().ComputeHash(Encoding.Default.GetBytes(context.Password))).Replace("-", "");


                //    cmd.Parameters.AddWithValue("pwd", pwd);

                //    conn.Open();
                //    using (SqlDataReader reader = cmd.ExecuteReader())
                //    {
                //        while (reader.Read())
                //        {
                //        user = new ApplicationUser { UserName = reader["user_name"]?.ToString() };
                //        }
                //    }
                //}
                // }
                IUnitOfWork  unitOfWork  = new UnitOfWork();
                UserService  userService = new UserService(unitOfWork);
                SignInDetail signin      = new SignInDetail();
                LoginDetail  loginResult = new LoginDetail();
                signin.Email           = context.UserName;
                signin.Password        = context.Password;
                signin.PasswordResetOn = passwordResetOn;
                loginResult            = userService.SignIn(signin);

                return(loginResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        public AjaxResult Login(SignInDetail signinDetail)
        {
            AjaxResult ajaxResult = new AjaxResult();

            //HttpManager httpManager = new HttpManager();


            try
            {
                if (signinDetail.LoginType == LoginType.Facebook)
                {
                    string facebookUrl = "https://graph.facebook.com/me?fields=id&access_token=" + signinDetail.AccessToken;
                    FacebookTokenResult facebookTokenResult = HttpManager.GetResult <FacebookTokenResult>(facebookUrl);
                    if (facebookTokenResult.Id != null)
                    {
                        ajaxResult.Message = "Login Success";
                        ajaxResult.Result  = true;
                        ajaxResult.Status  = Status.Success;

                        FormsAuthentication.SetAuthCookie(signinDetail.UserName, false);
                    }
                    else
                    {
                        ajaxResult.Message = "Login Failed";
                        ajaxResult.Result  = false;
                        ajaxResult.Status  = Status.Failure;

                        return(ajaxResult);
                    }

                    return(ajaxResult);
                }
                else if (signinDetail.LoginType == LoginType.Google)
                {
                }
                else if (signinDetail.LoginType == LoginType.CodeFinder)
                {
                    string validationMessage = "";
                    bool   valdiationPassed  = true;

                    if (signinDetail.UserName == "")
                    {
                        valdiationPassed  = false;
                        validationMessage = "Username Empty";
                    }

                    if (signinDetail.Password == "")
                    {
                        valdiationPassed  = false;
                        validationMessage = "Password Empty";
                    }

                    if (!valdiationPassed)
                    {
                        ajaxResult.Message = validationMessage;
                        ajaxResult.Result  = false;
                        ajaxResult.Status  = Status.Success;

                        return(ajaxResult);
                    }

                    bool isAuthenticated = Membership.ValidateUser(signinDetail.UserName, signinDetail.Password);

                    if (isAuthenticated)
                    {
                        ajaxResult.Message = "Login Success";

                        ProfileBase profile = ProfileBase.Create(signinDetail.UserName);

                        ajaxResult.Result = new UserProfile {
                            Email    = signinDetail.UserName,
                            FullName = (string)profile.GetPropertyValue("FullName")
                        };

                        ajaxResult.Status = Status.Success;

                        FormsAuthentication.SetAuthCookie(signinDetail.UserName, false);

                        return(ajaxResult);
                    }
                    else
                    {
                        ajaxResult.Message = "Login Failed";
                        ajaxResult.Result  = false;
                        ajaxResult.Status  = Status.Failure;

                        return(ajaxResult);
                    }
                }
                else
                {
                    ajaxResult.Message = "Invalid Login Type";
                    ajaxResult.Status  = Status.Failure;
                    return(ajaxResult);
                }

                ajaxResult.Status  = Status.Failure;
                ajaxResult.Message = "Unknown Error";

                return(ajaxResult);
            }
            catch (Exception ex)
            {
                ajaxResult.Message = ex.Message;
                ajaxResult.Status  = Status.Failure;
                return(ajaxResult);
            }
        }