Exemplo n.º 1
0
        public ActionResult Login(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(RedirectToAction("Index"));
            }

            DomainInstance databseHandler = new DomainInstance();

            if (databseHandler.GetUser(username, false) == null)
            {
                return(RedirectToAction("Index", new { LoginErrorMessage = TextDictionary.LLoginWrongUsernameOrPasswordMessage }));
            }

            var signInManager = HttpContext.GetOwinContext().Get <SignInManager>();
            var userManager   = HttpContext.GetOwinContext().Get <UserManager>();

            var signInStatus = signInManager.PasswordSignIn(username, password, true, false);

            if (!userManager.IsEmailConfirmedAsync(username).Result)
            {
                return(RedirectToAction("Index", new { LoginErrorMessage = TextDictionary.LLoginActivateAccountMessage }));
            }

            if (signInStatus == SignInStatus.Success)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("Index", new { LoginErrorMessage = TextDictionary.LLoginWrongUsernameOrPasswordMessage }));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Use this api method to check if a username is valid or not for registration
        /// </summary>
        /// <param name="username">Username which must be checked</param>
        /// <returns></returns>
        public HttpResponseMessage ValidateUsername(string username)
        {
            var response = new HttpResponseMessage();

            response.Content = null;

            DomainInstance handler = new DomainInstance();

            if (handler.GetUser(username, false) != null)
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = false,
                    Message = Resources.text.TextDictionary.LRegisterInvalidUsernameInputMessage
                }.JSONSerialize());
            }

            if (response.Content == null)
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = true
                }.JSONSerialize());
            }

            response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Use this api method to check if a email is valid or not for registration
        /// </summary>
        /// <param name="username">Username which must be checked</param>
        /// <returns></returns>
        public HttpResponseMessage ValidateEmail(string email)
        {
            var response = new HttpResponseMessage();

            Func <HttpResponseMessage, HttpResponseMessage> setContentType = (httpResponse) => {
                httpResponse.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                return(httpResponse);
            };

            if (!new EmailAddressAttribute().IsValid(email))
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = false,
                    Message = TextDictionary.LRegisterInvalidEmailFormatInputMessage
                }.JSONSerialize());

                return(setContentType(response));
            }

            DomainInstance handler = new DomainInstance();

            if (handler.GetUser(email, true) != null)
            {
                response.Content = new StringContent(new RegisterValidationResult()
                {
                    IsValid = false,
                    Message = Resources.text.TextDictionary.LRegisterInvalidEmailInputMessage
                }.JSONSerialize());

                return(setContentType(response));
            }


            response.Content = new StringContent(new RegisterValidationResult()
            {
                IsValid = true
            }.JSONSerialize());

            return(setContentType(response));
        }